https://gist.github.com/dmaze/308034415354fb0ec2e537157b3a39b8 is a minimal dry-system script that reads an integer value from an environment variable (using the :settings
feature). If I run the script like
AN_INT=10 ruby ./dry-rb-env.rb
it will print out the number like I expect. But if I either
AN_INT=foo ruby ./dry-rb-env.rb
unset AN_INT; ruby ./dry-rb-env.rb
I get rather long backtraces that don’t mention the variable name at all.
Three questions:
(1) Is there a good way to trap these errors and give a succinct error message (something like AN_INT: invalid value for Integer(): "foo"
would be great)?
(2) When I do report that, can I distinguish “missing” from “invalid”? (AN_INT is required
, not AN_INT: can't convert nil into Integer
)
(3) The value type has a .default(17)
value, so shouldn’t that get picked up?