Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Ruby Event Store Browser not loading events because of nil error #762

Closed
xhs345 opened this issue Sep 15, 2020 · 8 comments
Closed

Ruby Event Store Browser not loading events because of nil error #762

xhs345 opened this issue Sep 15, 2020 · 8 comments

Comments

@xhs345
Copy link

xhs345 commented Sep 15, 2020

The API call to load events is returning a 500 error for me and I'm unsure what is wrong.

NoMethodError - undefined method `iso8601' for nil:NilClass:

in https://github.com/RailsEventStore/rails_event_store/blob/v1.1.1/ruby_event_store-browser/lib/ruby_event_store/browser/json_api_event.rb#L32

I tested with both 1.0.0 and 1.1.1.

An example metadata entry of the batch that is parsed.

---
:timestamp: 2020-09-14 14:14:28.791973839 Z

Screenshot of all records that are loaded in the batch.

Screen Shot 2020-09-14 at 5 05 22 PM

Setup is pretty standard otherwise, not using custom serializer or similar

@mostlyobvious
Copy link
Member

mostlyobvious commented Sep 15, 2020

Can you please double-check that you don't have ---\n:timestamp:\n in metadata row?

Error message would suggest there was :timestamp key in metadata, however its value was nil.

SELECT id from event_store_events WHERE metadata LIKE "%:timestamp:\n%"

@xhs345
Copy link
Author

xhs345 commented Sep 16, 2020

I know, it's quite strange. I can see the query that was run before the error in the console and it returns the rows shown above. Also to double check I ran the following query on my database to ensure I have a timestamp entry for each record with some date:

SELECT event_store_events.* FROM event_store_events WHERE (event_store_events.metadataNOT LIKE '%timestamp: 2020%' ANDevent_store_events.metadata NOT LIKE '%timestamp: 2019%')

and got no results back

@mostlyobvious
Copy link
Member

Is there a way you could recreate this error in a sample app?

@xhs345
Copy link
Author

xhs345 commented Sep 20, 2020

I'll give it a try!

@mostlyobvious
Copy link
Member

  1. Full backtrace would definitely help
  2. Are you perhaps using your own Event class or the one from https://github.com/RailsEventStore/cqrs-es-sample-with-res/blob/5e25050f572a0563cc550e528d96def74cb329a9/lib/event.rb? I've received similar report today

@xhs345

@xhs345
Copy link
Author

xhs345 commented Dec 10, 2020

Yes, we mostly copied the event class from your demo project (I think the only difference is that we named it AppEvent).
I'll try to add a full backtrace

@mostlyobvious
Copy link
Member

It all comes to https://github.com/RailsEventStore/cqrs-es-sample-with-res/blob/0de944cf7fa31ba26ee1572b3ccb4d3215b14aed/lib/event.rb#L7

There are several lessons to unpack from it:

  • never use rescue nil even if you think you’re covered, legit errors got swallowed
  • Time.parse(metadata.delete(:timestamp)) works fine when you expect metadata value to be transformed by JSON.dump into string (the case of cqrs-es-sample app and its choice of mapper/database columns of jsonb) but fails miserably on YAML and Time

I have newer implementation of dry-struct event to share from commercial project, that eventually would become a gem.
RES 2.0 is going to handle timestamps differently, so that choice of metadata serialization does not really matter anymore (#674)

For now please change your AppEvent.new to following:

  def self.new(data: {}, metadata: {}, **rest)
    super(rest.merge(data).merge(metadata: metadata))
  end

@xhs345
Copy link
Author

xhs345 commented Dec 16, 2020

Thanks, will give that a try!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants