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

Improve panic message of autocfg::new #29

Closed
wants to merge 1 commit into from

Conversation

taiki-e
Copy link

@taiki-e taiki-e commented Oct 30, 2020

No description provided.

@cuviper
Copy link
Owner

cuviper commented Oct 30, 2020

Do you have an example of how this looks with a real error, before and after?

If the problem is just the verbosity of derive(Debug), we could implement that manually to look more like Display.

@taiki-e
Copy link
Author

taiki-e commented Oct 31, 2020

Do you have an example of how this looks with a real error, before and after?

Here is the current output and the output after this PR has been applied:

  • ErrorKind::Io:

    Before:
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Io(Os { code: 2, kind: NotFound, message: "No such file or directory" }) }', autocfg/src/lib.rs:137:28
    After:
    thread 'main' panicked at 'No such file or directory (os error 2)', autocfg/src/lib.rs:146:47
    
  • ErrorKind::Num:

    Before:
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Num(ParseIntError { kind: InvalidDigit }) }', autocfg/src/lib.rs:137:28
    After:
    thread 'main' panicked at 'invalid digit found in string', autocfg/src/lib.rs:146:47
    
  • ErrorKind::Utf8:

    Before:
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Utf8(Utf8Error { valid_up_to: 1, error_len: Some(1) }) }', autocfg/src/lib.rs:137:28
    After:
    thread 'main' panicked at 'invalid utf-8 sequence of 1 bytes from index 1', autocfg/src/lib.rs:146:47
    
  • ErrorKind::Other:

    Before:
    thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: Error { kind: Other("could not find rustc release") }', autocfg/src/lib.rs:137:28
    After:
    thread 'main' panicked at 'could not find rustc release', autocfg/src/lib.rs:146:47
    

If the problem is just the verbosity of derive(Debug), we could implement that manually to look more like Display.

I think verbosity is the main problem, but I think the output of .unwrap (i.e., "called Result::unwrap() on an Err value:") is also verbose. Here is output if use fmt::Display::fmt in Debug impl:

thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: No such file or directory (os error 2)', autocfg/src/lib.rs:137:28
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: invalid digit found in string', autocfg/src/lib.rs:137:28
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: invalid utf-8 sequence of 1 bytes from index 1', autocfg/src/lib.rs:137:28
thread 'main' panicked at 'called `Result::unwrap()` on an `Err` value: could not find rustc release', autocfg/src/lib.rs:137:28

@taiki-e
Copy link
Author

taiki-e commented Dec 26, 2021

Closing -- I no longer need this as I replaced all use of autocfg::new with autocfg::AutoCfg::new like crossbeam-rs/crossbeam#604.

@taiki-e taiki-e closed this Dec 26, 2021
@taiki-e taiki-e deleted the panic-msg branch December 26, 2021 10:18
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.

None yet

2 participants