TurtleAI / derive

An Event Sourcing and CQRS solution.
0 stars 1 forks source link

No clause matching in `Derive.PartitionDispatcher.handle_info/2` #28

Open rwillians opened 1 year ago

rwillians commented 1 year ago
02:01:37.726 [error] GenServer {:"Elixir.Hatch.Invoices.Service.supervisor", {Hatch.Invoices.Service, "30975810790621495645780525318144"}} terminating
** (FunctionClauseError) no function clause matching in Derive.PartitionDispatcher.handle_info/2
    (derive 0.1.0) lib/derive/partition_dispatcher.ex:80: Derive.PartitionDispatcher.handle_info({[:alias | #Reference<0.2816401368.3219980290.154724>], :ok}, %Derive.PartitionDispatcher{awaiters: [{{#PID<0.1092.0>, [:alias | #Reference<0.2816401368.3219980290.155007>]}, "30975811344411199482614974382080"}], options: %Derive.Options{batch_size: 100, logger: &Derive.Logger.IOLogger.log/1, mode: :catchup, name: Hatch.Invoices.Service, reducer: Hatch.Invoices.Service, show_progress: nil, source: :"Elixir.Hatch.Invoices.Service.source", validate_version: nil}, partition: %Derive.Partition{cursor: "30975810790842856574665039937536", error: nil, id: "30975810790621495645780525318144", status: :ok}, timeout: 30000})
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {[:alias | #Reference<0.2816401368.3219980290.154724>], :ok}

After a couple hours of try-and-error, somehow, I managed to get it "fixed" locally by adding this:

# PartitionDispatcher at line 88
def handle_info({_from, :ok}, %S{timeout: timeout} = state) do
  {:noreply, state, timeout}
end

I'm not sure of what I did there -- brain fried after debugging most the code base kkkry --, I just copied and past a bunch of things till get that working.

Failure was triggered when awaiting an event inside a service (weird thing is that we didn't catch that error before)

# Hatch.Invoice.Service
def handle_event(%TimeEntryCreated{} = e) do
  # commenting out this `await_processed/2` is enough to not get the error on derive but,
  # of course, the service will fail if the time entry doesn't exist in the db yet.
  await_processed([e], :reducers)

  with_time_entry(e.time_entry_id, &maybe_create_invoice_line_item/1)
end

Edit: ok, maybe that wasn't a "fix" cuz now I'm getting theses errors all over the place (although for some coincidence most tests are passing)

02:27:33.012 [error] GenServer :"Elixir.Hatch.Contracts.Service.source" terminating
** (FunctionClauseError) no function clause matching in anonymous fn/1 in Turtle.EventLog.handle_cast/2
    (turtle 0.0.1) lib/event_log.ex:102: anonymous fn(nil) in Turtle.EventLog.handle_cast/2
    (elixir 1.13.4) lib/enum.ex:4034: Enum.filter_list/2
    (turtle 0.0.1) lib/event_log.ex:102: Turtle.EventLog.handle_cast/2
    (stdlib 4.0.1) gen_server.erl:1120: :gen_server.try_dispatch/4
    (stdlib 4.0.1) gen_server.erl:1197: :gen_server.handle_msg/6
    (stdlib 4.0.1) proc_lib.erl:240: :proc_lib.init_p_do_apply/3
Last message: {:"$gen_cast", {:new_events, [nil, nil]}}
#  seems to repeat for all domains' service/reducer

The tests that seems to produce the most amount of errors is api/test/features/hatch__invoices_test.exs, at scenario "Invoices Only seller-admin in a contract can issue invoice".

rwillians commented 1 year ago

cc @venkatd