Emitting an event to same stream null reference exception

Hi,

When I try to emit an event to the same stream as the originating
stream I receive a null reference exception in the ES:

[12748,16,22:03:16.977] Error while processing message
EventStore.Core.Messages.ClientMessage+ReadStreamEventsBackwardCo
mpleted in queued handler 'Projection Core #2'.
Object reference not set to an instance of an object.

It is throwed at:
EventStore.Projections.Core.Services.Processing.EventByTypeIndexPositionTagger.AdjustTag(CheckpointTag
tag) in c:\_\eventstore\EventStore\src\EventStore\EventStore.Projections.Core\Services\Processing\EventByTypeIndexPositionTagger.cs:line
106

Because the 'tag' parameter is null

It is easy reproducible with an empty ES and following projection:

fromAll()
    .when({
        ChatMessage: function(s, e) {
            emit(e.streamId, 'ChatMessageReceived', {});
            return s;
        },
    })

Just enter a ChatMessage in the chat demo app...

I'm using the ES3.0RC btw.

HTH

Tim

Tim,

thank you I’ll check this.

-yuriy

Shouldnt be doing this. My guess is we should give an error at this point.

Any update on this one?

Btw, when I try the latest version from the master I get this error
when adding a new projection:

SyntaxError: Duplicate data property in object literal not allowed in
strict mode

Even with the default projection from the UI

Tim,

yes I can reproduce the problem. Looking into the problem.

I’m sorry for not answering earlier.

-yuriy

Tim,

there are two parts of the problem:

  1. there is a bug in the system with handling emits to non-empty streams created outside of the projection system. I’ll fix it.

  2. however, what you do is emitting event into a stream that is also written by the chat-demo. This is unsupported scenario. The projections subsystem cannot guarantee a recovery process for the projection in this case. Even if I fix the problem the next attempt to emit to this stream will result in another error saying that the stream was modified outside of the projection.

What are you trying to achieve?

-yuriy

Hi Yuriy,

Thanks for the response.

I'm not sure I really understand the problem. So it is not possible to
write to the stream of which the handling events belongs to?

What I try to do is to put more (business) logic in a projection, that
emits new events to the originating stream.

An basic example would be: (from another question on the list)

fromCategory('Alert')
   .foreachStream()
   .when({
        $init: function () {
            return { resolved: false };
        },

        Resolved: function(s, e) {
            s.resolved = true;
            return s;
        },

        Alerted: function(s, e) {
            if (!s.resolved)
            {
                emit(e.streamId, 'Unresolved', {});
            }
            return s;
        },
    });

And another thing I'm experimenting with is to place my aggregate
logic in a projection. It handles commands (which are also events),
and emits events to the same aggregate stream. I'm not sure if this is
a use-case for ES projections. But I can see some nice benefits in
doing this, like native hosting in ES and distribution. Are there
reasons why I shouldn't' do this?

If this this is not possible, I can try to split the stream in an
Order-Events and Order-Commands. Would that be a problem?

A current, not yet tested, Order aggregate example can be found here:
https://gist.github.com/tim-cools/9428193

Any feedback welcome.

Tim