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

Migrator obscures stack trace of unhandled exceptions #422

Closed
digitalcora opened this issue Jul 11, 2020 · 3 comments · Fixed by #577
Closed

Migrator obscures stack trace of unhandled exceptions #422

digitalcora opened this issue Jul 11, 2020 · 3 comments · Fixed by #577
Assignees
Labels
improve error experience Make errors nicer to deal with

Comments

@digitalcora
Copy link

digitalcora commented Jul 11, 2020

Trying to set up a Lucky project for the first time, I ran into a strange error that took quite a while to debug. Part of the difficulty was that it turned out Avram was suppressing the real stack trace of the error.

in https://github.com/luckyframework/avram/blob/63be781/src/avram/migrator/migrator.cr:

module Avram::Migrator
  def self.run
    yield
  rescue e : PQ::PQError
    raise e.message.colorize(:red).to_s
  rescue e : Exception   # <=
    raise e.message.to_s # <=
  end
end

The marked lines catch all exceptions and re-raise them, with a stack trace pointing here instead of the original source. The purpose of these lines is unclear to me, and in fact once I deleted them from my project's copy of Avram in lib, I got a much better stack trace that allowed me to solve the problem.

If there would be no harm in doing so, maybe these lines could be removed?

@jwoertink
Copy link
Member

Hey @digitalcora Welcome to Lucky! Sorry you ran in to some issues. Hopefully you got it all set now.

That is a good call. Normally when we catch errors like that, it's because we can usually provide a better error message than the one provided by Crystal's default. In this case since we're just re-raising the same error, I'm not seeing any benefit to having it. My guess is that it would be ok to remove those. What are your thoughts @paulcsmith ?

@paulcsmith
Copy link
Member

I think the original reason was to highlight the error in red. But if it makes the stacktrace worse then we should remove it :D Thanks for opening the issue @digitalcora!

@jwoertink jwoertink added the improve error experience Make errors nicer to deal with label Jul 16, 2020
@matthewmcgarvey
Copy link
Member

These are also places I believe are obscuring problems during migrations:

rescue e : Exception
raise "Unexpected error while running migrations: #{e.message}".colorize(:red).to_s

rescue e : PQ::PQError
raise <<-ERROR
There was a problem running this statement:
#{statements.join("\n")}
Problem:
#{e.message}
ERROR

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
improve error experience Make errors nicer to deal with
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants