Skip to content

Conversation

@odarriba
Copy link
Contributor

This change expands the ErrorTracker.Error.new/2 API to allow receiving exceptions in three ways:

  1. {kind, reason}
  2. {kind, exception}
  3. exception

If a exception is received (either with a kind or not):

  • the kind field is set to the struct of the exception.
  • the reason field is set to the message of the exception.

If a {kind, reason} is received:

  • the kind field is set to the kind value converted to string.
  • the reason field is set to the reason value converted to string.

Aside from that, the dev server now includes another route to generate an EXIT signal to thest this.

@odarriba odarriba requested a review from crbelaus June 12, 2024 16:41
@odarriba odarriba self-assigned this Jun 12, 2024
@odarriba odarriba force-pushed the improve-errors-kind branch from d9b6284 to e61bc5d Compare June 18, 2024 13:37
@odarriba odarriba force-pushed the improve-errors-kind branch from 0d8e0bb to c949d90 Compare June 18, 2024 13:45
@odarriba
Copy link
Contributor Author

This one is ready to be reviewed again @crbelaus

Comment on lines 29 to 32
%{__struct__: struct} = ex when is_exception(ex) ->
{to_string(struct), Exception.message(ex)}

{_kind, %{__struct__: struct} = ex} when is_exception(ex) ->
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Super minor suggestion for readability:

Suggested change
%{__struct__: struct} = ex when is_exception(ex) ->
{to_string(struct), Exception.message(ex)}
{_kind, %{__struct__: struct} = ex} when is_exception(ex) ->
%struct{} = ex when is_exception(ex) ->
{to_string(struct), Exception.message(ex)}
{_kind, %struct{} = ex} when is_exception(ex) ->

@crbelaus
Copy link
Contributor

I was just trying it and it works great. Just added an optional comment that can be ommitted.

Looks good to me!

@odarriba odarriba force-pushed the improve-errors-kind branch from 614c2bc to f8674c3 Compare June 18, 2024 14:11
@odarriba odarriba merged commit 9f2f6fb into main Jun 18, 2024
@odarriba odarriba deleted the improve-errors-kind branch June 18, 2024 14:20
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

Successfully merging this pull request may close these issues.

3 participants