Skip to content
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

Be more robust when weird arguments are passed in #153

Merged
merged 1 commit into from
Nov 9, 2022

Conversation

matklad
Copy link
Contributor

@matklad matklad commented Nov 9, 2022

Two cases here:

  • invalid utf8 -- this can happen in somewhat reasonable circumstances, so returning a graceful error is warranted here
  • empty argv -- this one is weird, I think various things across the stack try to actually patch that up to never bubble empty argv to an application, but it's not to hard to add extra error handling here https://ryiron.wordpress.com/2013/12/16/argv-silliness/

Before:

01:22:39|~/p/argh|master✓
λ cargo run --example simple_example -- \Xff
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/simple_example '�'`
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: "\xFF"', library/std/src/env.rs:805:51
stack backtrace:
   0: rust_begin_unwind
             at /rustc/e080cc5a659fb760c0bc561b722a790dad35b5e1/library/std/src/panicking.rs:575:5
   1: core::panicking::panic_fmt
             at /rustc/e080cc5a659fb760c0bc561b722a790dad35b5e1/library/core/src/panicking.rs:65:14
   2: core::result::unwrap_failed
             at /rustc/e080cc5a659fb760c0bc561b722a790dad35b5e1/library/core/src/result.rs:1791:5
   3: core::result::Result<T,E>::unwrap
             at /rustc/e080cc5a659fb760c0bc561b722a790dad35b5e1/library/core/src/result.rs:1113:23
   4: <std::env::Args as core::iter::traits::iterator::Iterator>::next::{{closure}}
             at /rustc/e080cc5a659fb760c0bc561b722a790dad35b5e1/library/std/src/env.rs:805:35

After:

λ cargo run --example simple_example -- \Xff
    Finished dev [unoptimized + debuginfo] target(s) in 0.01s
     Running `target/debug/examples/simple_example '�'`
Invalid utf8: �

@matklad
Copy link
Contributor Author

matklad commented Nov 9, 2022

tests seem to be broken on master: #154

Two cases here:

- invalid utf8 -- this can happen in somewhat reasonable circumstances,
  so returning a graceful error is warranted here
- empty `argv` -- this one is weird, I think various things across the
  stack try to actually patch that up to never bubble empty argv to an
  application, but it's not to hard to add extra error handling here
  <https://ryiron.wordpress.com/2013/12/16/argv-silliness/>
@sadmac7000 sadmac7000 merged commit f43107f into google:master Nov 9, 2022
@matklad matklad deleted the silly-args branch November 9, 2022 22:17
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants