-
Notifications
You must be signed in to change notification settings - Fork 120
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
Avoid rescuing argument error in next node blocks #2032
Avoid rescuing argument error in next node blocks #2032
Conversation
This is in preparation for removing the `rescue ArgumentError` statement from `SmartAnswer::Flow#process`. Rescuing `ArgumentError` makes it easy to mask real exceptions in the code in our `next_node` blocks. I think one of the legitimate reasons to rescue `ArgumentError` at the moment is because they can be raised by bad user input in this method. Raising `InvalidResponse` instead seems like the right thing to do and should allow me to stop rescuing `ArgumentError`.
This is in preparation for removing the `rescue ArgumentError` statement from `SmartAnswer::Flow#process`. Rescuing `ArgumentError` makes it easy to mask real exceptions in the code in our `next_node` blocks. I think one of the legitimate reasons to rescue `ArgumentError` at the moment is because they can be raised by bad user input in this method. Raising `InvalidResponse` instead seems like the right thing to do and should allow me to stop rescuing `ArgumentError`.
I don't think it's a good idea to rescue from such a generic exception in our `next_node` blocks. It hides real problems in our Ruby code and makes them look as though the user has entered invalid data in the Smart Answer. The rescuing of ArgumentError caused me problems twice recently. Once when I was comparing a Date with a String and once when I was calling a method with incorrect arguments. This change will mean that errors such as this cause the application to fail fast. >> Date.today < '2016-01-01' ArgumentError: comparison of Date with String failed >> def foo(arg); end => :foo >> foo() ArgumentError: wrong number of arguments (0 for 1) The two preceeding commits ("Raise InvalidResponse when parsing Integers in Value#parse_input" and "Raise InvalidResponse when parsing Floats in Value#parse_input") should have removed the only places where we were raising an `ArgumentError` in response to bad user input.
It looks as if there may be other places explicitly raising
Also I wonder whether it's worth inspecting the message of the legitimately rescued Apart from the above, this looks great to me! 👍 |
I've already addressed this in the description of this PR. Essentially, I don't think we need to worry about it. This is the same as the first example above, so I don't think we need to worry about it. I've updated the description of this PR to include this case as well. This |
Fair do's. Apologies if I missed the explanation in the PR description first time round. Look good to me 👍 |
I guess my thinking was to replicate the |
…in-next-node-blocks Avoid rescuing argument error in next node blocks
I don't think it's a good idea to rescue from such a generic exception in our
next_node
blocks. It hides real problems in our Ruby code and makes them lookas though the user has entered invalid data in the Smart Answer.
The rescuing of ArgumentError caused me problems twice recently. Once when I was
comparing a Date with a String and once when I was calling a method with
incorrect arguments. This change will mean that errors such as this cause the
application to fail fast.
The first two commits ("Raise InvalidResponse when parsing Integers in
Value#parse_input" and "Raise InvalidResponse when parsing Floats in
Value#parse_input") should have removed the only places where we were raising
an
ArgumentError
in response to bad user input.We're still raising an
ArgumentError
fromSmartAnswer::Calculators::VatPaymentDeadlines#last_payment_date
and#funds_recevied_by
. I haven't changed these because I don't believe this error will ever be raised by code in anext_node
block. The error can only be raised by#last_payment_date
and#funds_received_by
if an option other than one of those listed in themultiple_choice
options for the:how_do_you_want_to_pay?
question is entered, and in that case theSmartAnswer::Question::MultipleChoice#parse_input
method will raise anInvalidResponse
exception first.I ran all the regression tests locally against this change and didn't see any errors. That's no guarantee that we won't see problems if/when this is deployed to production.
Expected changes