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

Exit better than throw #71

Merged
merged 3 commits into from
Mar 7, 2017
Merged

Exit better than throw #71

merged 3 commits into from
Mar 7, 2017

Conversation

lucafavatella
Copy link

Depends on PR #70.

Before merging this PR, go over this checklist:

  • The issue was approved by a considerable number of votes
  • The rule is listed in the table of contents
  • The rule text respects the structure:
    • Title
    • Short Description
    • Examples
    • Reasoning
  • It provides links to examples in code for
    • good scenarios
    • bad scenarios

catch
_:Error ->
lager:error("Error here: ~p~n"
" Arguments: ~p~n"
" Stack: ~p", [Error, WithThis, erlang:get_stacktrace()]),
{error, Error}
end.

good2(WithThis) ->
Copy link
Member

Choose a reason for hiding this comment

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

According to Xref:

loud_errors:good2/1 calls undefined function something:that/3

throw({error, Error})
end.

good1(WithThis) ->
Copy link
Member

Choose a reason for hiding this comment

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

According to Xref:

loud_errors:good1/1 calls undefined function lager:error/2


bad(WithThis) ->
bad1(WithThis) ->
Copy link
Member

Choose a reason for hiding this comment

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

According to Xref:

loud_errors:bad1/1 calls undefined function something:that/3

try
something:that(may, fail, WithThis)
catch
_:Error ->
{error, Error}
end.

good(WithThis) ->
bad2(WithThis) ->
Copy link
Member

Choose a reason for hiding this comment

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

According to Xref:

loud_errors:bad2/1 calls undefined function something:that/3

throw({error, Error})
end.

good1(WithThis) ->
Copy link
Member

Choose a reason for hiding this comment

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

According to Xref:

loud_errors:good1/1 calls undefined function something:that/3

@lucafavatella
Copy link
Author

I propose this as I plan to replace several throw in sumo.erl (see #70 (comment) for context) with exit - that at least has stacktrace. I understand errors shall be more structured (e.g. logging error and returning tuple value tagged with error) but exit appears to me to be good-enough - for sure better than throw.

Feel feel to close straight away if you feed exit not to be good enough.

@elbrujohalcon elbrujohalcon merged commit 7257aa0 into inaka:master Mar 7, 2017
@lucafavatella lucafavatella deleted the exit-better-than-throw branch March 7, 2017 13:59
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