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

Catching of Main::Parameter::NoneSuch exception #28

Open
joonty opened this issue Jan 30, 2013 · 0 comments
Open

Catching of Main::Parameter::NoneSuch exception #28

joonty opened this issue Jan 30, 2013 · 0 comments

Comments

@joonty
Copy link

joonty commented Jan 30, 2013

Hi,

Thanks for an excellent tool.

I have a question about the behaviour of catching exceptions, specifically the exception thrown when trying to access a parameter that doesn't exist. The exception thrown is Main::Parameter::NoneSuch, and the exception message is the string representation of the key used with the params object. This is fine, except for the fact that Main catches the exception and simply prints out the exception message, which doesn't have any context associated with it.

Reading that back, it may be a little hard to understand what I mean. So here's an example:

Main {
  def run
    # Try to access non-existent param
    params[:nothing]
  end
}

The output of this:

$ ruby example.rb
nothing

If you're not used to working with Main you could end up tearing you hair out, trying to work out why your program has stopped running and it's now spitting out a single word (this may or may not have happened to me).

I would propose either re-raising the exception (it certainly is exceptional behaviour, and it should only ever happen in development) or at least printing the exception class name, e.g. Main::Parameter::NoneSuch => nothing. Or perhaps catch that exception specifically and print out a helpful message.

I'm happy to fork and code a possible solution if you would be willing to look over it?

Thanks

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

1 participant