You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Can you reason with me why your approach is superior to:
defnormalize_phone_number(num)Phony.normalize(num)rescueerrors.add(:base,"#{num} is not a valid number")end
Your approach enables people to also rescue from other types of exceptions. There are two cases where this is useful:
Calling a given method (ie. Phony.normalize) can raise multiple types of exception, and discerning them is important. This is not the case. Phony simply fails if there is not enough information, and cannot discern why easily.
More code than Phony.normalize(num) is called, which may raise other types of exceptions. Personally, I'd like to discourage people from bunching code up that can throw multiple exceptions.
Also see https://github.com/floere/phony#normalizing: "This will often raise an error if you try normalizing a non E164-izable number (a number that does not contain enough information to be normalized into an E164 conform number). Use Phony.plausible? for checking if it can be normalized first."
But please disagree – I really welcome well-reasoned disagreement :)
If you pass normalize a value it can't process, the following exception gets raised:
It seems like Phony should raise a more useful exception here that downstream code can reasonably deal with:
Happy to write a patch if you agree with this approach.
The text was updated successfully, but these errors were encountered: