-
-
Notifications
You must be signed in to change notification settings - Fork 1k
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
Clap panics on argument in invalid unicode #262
Comments
Caused by Using One solution could be: If the argument passed is not valid unicode, we could first check if it is a valid directory or file. If it isn't, then produce error. |
@remram44 Would you be okay with
|
I think it's kind of weird -- in the Rust stdlib, lossy functions are clearly marked as such, and that is not the case of Another option is to make get_matches_safe() return an error (not panic) on invalid unicode, and get_matches() print out a readable error message instead of the default panic text. |
@remram44 Partly tested (compiles; no tests for invalid Unicode chars yet) I have I might take an attempt to porting it over to Snapshot of current code for
I'm out for the night. zzZZZ |
@remram44 Returning a Result on invalid unicode should be an easy addition. If this works for you we can probably have this added by tomorrow with a new version out to crates.io It would also be easy to add a |
@kbknapp If we were to add this, we have to change the function signature of |
@remram44 #265 allows returning a Result |
@kbknapp Just a tip: |
|
Issue 262 - Result and Lossy options for invalid Unicode This allows not `panic!`ing on invalid unicode characters, and the option of returning lossy results. This does **not** turn all results into an `OsStr` preserving invalid unicode. If this helps with #262 we can merge (after review), otherwise we'll continue to discuss if there's a better way to handle this issue.
Oops. My haste. Sorry. edited previous comment Thanks. |
@remram44 try the latest master and let us know if it works for your use case. If so, we'll publish a new version to crates.io, close this issue, and open a more general unicode handling tracking issue. |
I can understand your library not being designed to handle arguments that are not valid unicode (which are possible on UNIX, and can be valid filenames, but heh), however having your library panic the calling thread is not cool. Please consider using Result instead of crashing.
Reproduce:
(note that you can't use
cargo run
, it can't handle unicode either (but at least it doesn't panic))Similar to rust-lang/getopts#30; I'm still looking for a safe argument-parsing library 😢
The text was updated successfully, but these errors were encountered: