Bug: emit! and require! macros fail to compile due to private module access #97

Closed
opened 2025-07-21 08:21:29 -07:00 by jwilger · 0 comments
jwilger commented 2025-07-21 08:21:29 -07:00 (Migrated from github.com)

Description

The emit! and require! macros documented in eventcore 0.1.3 fail to compile because they attempt to access private modules within the eventcore crate.

Steps to Reproduce

  1. Add eventcore dependencies to Cargo.toml:
eventcore = "0.1.3"
eventcore-macros = "0.1.3"
  1. Try to use the emit! macro in a command handler:
use eventcore::{emit, CommandLogic, CommandResult, ReadStreams, StreamWrite};

// In CommandLogic::handle implementation:
let mut events = Vec::new();
emit!(
    events,
    &read_streams,
    self.stream_id.clone(),
    DomainEvent::SomethingHappened { data: "test".into() }
);
  1. Try to use the require! macro for validation:
use eventcore::{require, CommandError};

// In CommandLogic::handle implementation:
require!(
    some_condition,
    "Business rule violation message"
);

Expected Behavior

Both macros should compile successfully and provide the documented functionality:

  • emit! should simplify event creation
  • require! should simplify business rule validation

Actual Behavior

Compilation fails with the following errors:

error[E0603]: module `command` is private
    --> /home/jwilger/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/eventcore-0.1.3/src/macros.rs:80:30
     |
80   |         $events.push($crate::command::StreamWrite::new(
     |                              ^^^^^^^ private module

error[E0603]: module `errors` is private
    --> /home/jwilger/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/eventcore-0.1.3/src/macros.rs:37:32
     |
37   |             return Err($crate::errors::CommandError::BusinessRuleViolation(
     |                                ^^^^^^ private module

Analysis

The macros are trying to access:

  • $crate::command::StreamWrite instead of $crate::StreamWrite
  • $crate::errors::CommandError instead of $crate::CommandError

Since these types are re-exported at the crate root but the modules themselves are private, the macro expansion fails.

Workaround

Until fixed, users can use the manual approach:

Instead of require!(condition, "error message"):

if !condition {
    return Err(CommandError::BusinessRuleViolation("error message".to_string()));
}

Instead of emit!(events, &read_streams, stream_id, event):

events.push(StreamWrite::new(&read_streams, stream_id, event)?);

Environment

  • eventcore version: 0.1.3
  • eventcore-macros version: 0.1.3
  • Rust version: (tested on stable)

This issue was discovered while implementing eventcore in the union_square project: https://github.com/jwilger/union_square/pull/107

The #[derive(Command)] macro from eventcore-macros works correctly - only the emit! and require! macros are affected.

## Description The `emit!` and `require!` macros documented in eventcore 0.1.3 fail to compile because they attempt to access private modules within the eventcore crate. ## Steps to Reproduce 1. Add eventcore dependencies to Cargo.toml: ```toml eventcore = "0.1.3" eventcore-macros = "0.1.3" ``` 2. Try to use the `emit!` macro in a command handler: ```rust use eventcore::{emit, CommandLogic, CommandResult, ReadStreams, StreamWrite}; // In CommandLogic::handle implementation: let mut events = Vec::new(); emit!( events, &read_streams, self.stream_id.clone(), DomainEvent::SomethingHappened { data: "test".into() } ); ``` 3. Try to use the `require!` macro for validation: ```rust use eventcore::{require, CommandError}; // In CommandLogic::handle implementation: require!( some_condition, "Business rule violation message" ); ``` ## Expected Behavior Both macros should compile successfully and provide the documented functionality: - `emit!` should simplify event creation - `require!` should simplify business rule validation ## Actual Behavior Compilation fails with the following errors: ``` error[E0603]: module `command` is private --> /home/jwilger/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/eventcore-0.1.3/src/macros.rs:80:30 | 80 | $events.push($crate::command::StreamWrite::new( | ^^^^^^^ private module error[E0603]: module `errors` is private --> /home/jwilger/.cargo/registry/src/index.crates.io-1949cf8c6b5b557f/eventcore-0.1.3/src/macros.rs:37:32 | 37 | return Err($crate::errors::CommandError::BusinessRuleViolation( | ^^^^^^ private module ``` ## Analysis The macros are trying to access: - `$crate::command::StreamWrite` instead of `$crate::StreamWrite` - `$crate::errors::CommandError` instead of `$crate::CommandError` Since these types are re-exported at the crate root but the modules themselves are private, the macro expansion fails. ## Workaround Until fixed, users can use the manual approach: Instead of `require!(condition, "error message")`: ```rust if !condition { return Err(CommandError::BusinessRuleViolation("error message".to_string())); } ``` Instead of `emit!(events, &read_streams, stream_id, event)`: ```rust events.push(StreamWrite::new(&read_streams, stream_id, event)?); ``` ## Environment - eventcore version: 0.1.3 - eventcore-macros version: 0.1.3 - Rust version: (tested on stable) ## Related This issue was discovered while implementing eventcore in the union_square project: https://github.com/jwilger/union_square/pull/107 The `#[derive(Command)]` macro from eventcore-macros works correctly - only the `emit!` and `require!` macros are affected.
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
jwilger/eventcore#97
No description provided.