mycognosist / solar

A minimal Secure Scuttlebutt replication node.
Other
20 stars 2 forks source link

Print more informative error message when user passes bad arguments #59

Closed black-puppydog closed 1 year ago

black-puppydog commented 1 year ago

This took me a little while to figure out and it was mostly because there's literally no feedback at all whe I pass a bad value. Example calls to try this with:

# should print an error message with this commit
cargo run -- --connect 'tcp://::1:8080?shs=O4CiyVLNWz6FgU3aTJEUo398O8k9GmEpCXEdriib9MI=.ed25519'

# fine before, and still fine now (note the [] around the IPv6 address)
cargo run -- --connect 'tcp://[::1]:8080?shs=O4CiyVLNWz6FgU3aTJEUo398O8k9GmEpCXEdriib9MI=.ed25519'
black-puppydog commented 1 year ago

I went with map_err() in this case because I didn't want to change the behaviour beyond printing. But of course, given how the rest of the function uses expect(), we might just as well go for that.

mycognosist commented 1 year ago

@black-puppydog

Awesome, thanks!

I haven't pushed any code yet but I'm currently working on a big refactor of the configuration system (including the CLI config). That will provide a good opportunity to handle these cases better. I intend on implementing a validate() method on the Cli struct so that any input errors can be caught immediately and clearly reported.

For the time being, I think your solution is sufficient so I'm going ahead with a merge.