Closed: Continuous projection: Always getting error: Value cannot be null. (Parameter 'causedByTag')

I am trying to make my first steps with continuous projections but most of the time I get the following
error:

The fp6_func projection failed to process an event. Handler: EventStore.Projections.Core.Services.Interpreted.JintProjectionStateHandler Event Position: fp6_proxyToFunc: 0 Message: Value cannot be null. (Parameter ‘causedByTag’)

This is the source of my projection:

options({
    //resultStreamName: "some_name",
    $includeLinks: false,
    reorderEvents: false,
    processingLag: 0
});

fromStream('fp6_proxyToFunc')
    .when({

        dummy0: function(unusedState, unusedEvent) {
            return 1;
        },

        dummy1: function(unusedState, unusedEvent) {
            return 7;
        },


        $init: function(unusedState, event) {

            emit('fp6_debug', 'func_dollarInit', { 'incomingEvent': event });


            // This projection has no state as it resembles a stateless external function
            return {
                "info": "This state is unused"
            };
        },

    })

The strange thing is that suddenly after after some seemingly random changes in the projection source it works. Until it doesn’t. I have no idea what I am dealing with here.

Help would be very much appreciated.

Heiner,

I would have to try it out for myself, but I don’t think there is an event available in $init. This would be used for initialising your state before the first event is processed.
You would only emit / linkTo etc from an event handler.

@heiner.bunjes , @steven.blair is right:
$init is called to create an inital state and has no parameters
example:
https://developers.eventstore.com/server/v21.10/projections.html#user-defined-projections

Thank you!
But this still doesn’t seem to solve my problem.

The source is now

// Version 9

options({
    //resultStreamName: "some_name",
    $includeLinks: false,
    reorderEvents: false,
    processingLag: 0
});

fromStream('fp6_proxyToFunc')
    .when({

        dummy0: function(unusedState, unusedEvent) {
            return 1;
        },

        dummy1: function(unusedState, unusedEvent) {
            return 7;
        },


        $init: function() {

            emit('fp6_debug/func', 'func_dollarInit', { "Info": "$init was called" });


            // This projection has no state as it resembles a stateless external function
            return {
                "info": "This state is unused"
            };
        },

        requestFromProxy: function(unusedState, event) {

        },

    })

But the error is still

The fp7_func projection failed to process an event. Handler: EventStore.Projections.Core.Services.Interpreted.JintProjectionStateHandler Event Position: fp6_proxyToFunc: 0 Message: Value cannot be null. (Parameter 'causedByTag')

I then let dummy0 and dummy1 return objects instead of numbers and the projection goes into state running. :grinning:
Is it possible that not returning an object as the new state throws the same error?

But to make it more interesting: Now my two projections despite being in state ‘running’ are not reacting to events in the streams they are subscribed to. :grimacing: Here is an image of one of those two projections:

Just to mention it in case it might be related: I have one projection that has been in state “stopping” for hours now. There seems to be nothing I can do about it.

Sorry that I can’t bring it more to the point but I really don’t see how or if my problems are related.
I have a long history as a programmer (a lot of functional programming), just not in javascript.

If you think that this unresponsive state is unrelated to the original topic I will open a new thread.

Don’t emit in the $init function, it’s only for setting initial state

Thanks!
Will try and answer.

No change

The source is now

// Version 13 web

options({
    //resultStreamName: "my_demo_projection_result",
    $includeLinks: false,
    reorderEvents: false,
    processingLag: 0,
});


fromStreams(["fp7_xToProxy"])
    .when({

        $init: function() {


            return {
                "algoBusy": false,
                "debug": "p2",
                "eventBuffer": []
            };

        },

        $any: function(state, event) {
            state = {
                "debug": "p3",
            };
        },
    })
    .transformBy(function(state) {
        return state;
    })
    .outputState()

And it is still not responding.

Try removing the square brackets, I am sure if you want to use multiple streams you would do:

fromStreams(‘stream1’,‘stream2’)

I created a new continuous projection named dummy

It is shown as running but it too is not responding to new messages (here in stream fp7_dummyIn).

It seems that the system has a problem and not just the specific projection.

And again: just in case it is related: I have one projection that has been in state “stopping” for hours now. There seems to be nothing I can do about it.

I had a short look at the server log files but I am not experienced enough with ESDB to make something useful of it.

I could post part of the log files here if that might help.

Some more Info: I updated to version 21.10.6.0 today. Before that it was 20.10.2.

Could you paste the projection code up. I think i see a couple of problems and might be easier If I show you that way.

Alternatively, give me a shout and Slack.

Great: So I propose to have a look at the “not really running projection” problem.

I created a new projection dummy1

fromStream('dummy')
    .when({

        $init: function() {
            return {
                a: true
            };
        },

    })

As you can see it is running but the state is empty. Shouldn’t it be filled with what $init returns?

So as it looks, the projections are not only not responding to events, they are not even initialized.

The projection is fine


Just try adding an event to the stream:

Two events are in the stream now.

And the state is initialized.

So is it correct that a projection is only initialized in reaction to the first event it receives? I obviously didn’t know that.

Yeah, exactly.
it needs “something” (an event) to start your projection