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

Better Debug impl for io::Error. #47120

Merged
merged 1 commit into from
Jan 15, 2018
Merged

Conversation

clarfonthey
Copy link
Contributor

@clarfonthey clarfonthey commented Jan 2, 2018

This PR includes the below changes:

  1. The former impl wrapped the entire thing in Error { repr: ... } which was unhelpful; this has been removed.
  2. The Os variant of io::Error included the code and message, but not the kind; this has been fixed.
  3. The Custom variant of io::Error included a Custom(Custom { ... }), which is now just Custom { ... }.

Example of previous impl:

Error {
    repr: Custom(
        Custom {
            kind: InvalidData,
            error: Error {
                repr: Os {
                    code: 2,
                    message: "no such file or directory"
                }
            }
        }
    )
}

Example of new impl:

Custom {
    kind: InvalidData,
    error: Os {
        code: 2,
        kind: NotFound,
        message: "no such file or directory"
    }
}

@rust-highfive
Copy link
Collaborator

r? @dtolnay

(rust_highfive has picked a reviewer for you, use r? to override)

Copy link
Member

@dtolnay dtolnay left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

@dtolnay
Copy link
Member

dtolnay commented Jan 2, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 2, 2018

📌 Commit f058dce has been approved by dtolnay

@clarfonthey
Copy link
Contributor Author

I forgot a stability attribute so you'll have to r+ again.

@dtolnay
Copy link
Member

dtolnay commented Jan 2, 2018

@bors r+

@bors
Copy link
Contributor

bors commented Jan 2, 2018

📌 Commit 418d050 has been approved by dtolnay

@frewsxcv
Copy link
Member

frewsxcv commented Jan 2, 2018

@bors rollup

@frewsxcv
Copy link
Member

frewsxcv commented Jan 2, 2018

[01:09:58] failures:
[01:09:58]     io::error::test::test_debug_error
[01:09:58] 
[01:09:58] test result: FAILED. 788 passed; 1 failed; 0 ignored; 0 measured; 0 filtered out

@bors r-

@kennytm kennytm added the S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author. label Jan 2, 2018
#[stable(feature = "rust1", since = "1.0.0")]
pub struct Error {
repr: Repr,
}

#[stable(feature = "io_error_debug", since = "1.24.0")]
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As Debug has been implemented for io::Error since 1.0.0 #[stable(feature = "rust1", since = "1.0.0")] would make more sense here.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Will do

@clarfonthey
Copy link
Contributor Author

I fixed the test, changed the stability attribute, and also added a kind field to the OS error debug considering how that wasn't included but could be useful.

@dtolnay
Copy link
Member

dtolnay commented Jan 3, 2018

Could you update your comment at the top of this thread with an accurate before and after? The after Os representation should include the new kind field and the Custom looks like it should be getting formatted as a tuple struct according to the code.

@clarfonthey clarfonthey force-pushed the io_error_debug branch 2 times, most recently from f84a6f2 to cb25cd5 Compare January 3, 2018 02:35
@clarfonthey
Copy link
Contributor Author

@dtolnay done! I also modified the failing test with one that's closer to the one listed in the OP.

}
};
let expected = format!(
"Custom { \
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Should be {{ here.

[01:18:41] error: invalid format string: expected `'}'`, found `'k'`
[01:18:41]    --> /checkout/src/libstd/io/error.rs:590:13
[01:18:41]     |
[01:18:41] 590 | /             "Custom { \
[01:18:41] 591 | |                 kind: InvalidInput, \
[01:18:41] 592 | |                 error: Os {{ \
[01:18:41] 593 | |                     code: {:?}, \
[01:18:41] ...   |
[01:18:41] 596 | |                 }} \
[01:18:41] 597 | |             }}",
[01:18:41]     | |_______________^

@clarfonthey clarfonthey force-pushed the io_error_debug branch 3 times, most recently from d011822 to fe3e8e2 Compare January 5, 2018 03:16
@clarfonthey
Copy link
Contributor Author

I'm fairly certain that I've fixed the build errors. Waiting on CI.

@dtolnay
Copy link
Member

dtolnay commented Jan 5, 2018

Travis says:

error[E0308]: mismatched types
   --> /checkout/src/libstd/io/error.rs:582:32
    |
582 |               repr: Repr::Custom(Custom {
    |  ________________________________^
583 | |                 kind: ErrorKind::InvalidInput,
584 | |                 error: box Error {
585 | |                     repr: super::Repr::Os(code)
586 | |                 },
587 | |             })
    | |_____________^ expected struct `realstd::boxed::Box`, found struct `io::error::Custom`
    |
    = note: expected type `realstd::boxed::Box<io::error::Custom>`
               found type `io::error::Custom`

@shepmaster
Copy link
Member

Ping from triage, @clarcharr! Will you have time to address the build issues?

@killercup
Copy link
Member

Build issue seems to be addressed, CI is green, so I'm gonna go ahead and

@bors r=dtolnay

@bors
Copy link
Contributor

bors commented Jan 14, 2018

📌 Commit 52e074e has been approved by dtolnay

GuillaumeGomez added a commit to GuillaumeGomez/rust that referenced this pull request Jan 14, 2018
Better Debug impl for io::Error.

This PR includes the below changes:

1. The former impl wrapped the entire thing in `Error { repr: ... }` which was unhelpful; this has been removed.
2. The `Os` variant of `io::Error` included the code and message, but not the kind; this has been fixed.
3. The `Custom` variant of `io::Error` included a `Custom(Custom { ... })`, which is now just `Custom { ... }`.

Example of previous impl:

```rust
Error {
    repr: Custom(
        Custom {
            kind: InvalidData,
            error: Error {
                repr: Os {
                    code: 2,
                    message: "no such file or directory"
                }
            }
        }
    )
}
```

Example of new impl:

```rust
Custom {
    kind: InvalidData,
    error: Os {
        code: 2,
        kind: NotFound,
        message: "no such file or directory"
    }
}
```
kennytm added a commit to kennytm/rust that referenced this pull request Jan 15, 2018
Better Debug impl for io::Error.

This PR includes the below changes:

1. The former impl wrapped the entire thing in `Error { repr: ... }` which was unhelpful; this has been removed.
2. The `Os` variant of `io::Error` included the code and message, but not the kind; this has been fixed.
3. The `Custom` variant of `io::Error` included a `Custom(Custom { ... })`, which is now just `Custom { ... }`.

Example of previous impl:

```rust
Error {
    repr: Custom(
        Custom {
            kind: InvalidData,
            error: Error {
                repr: Os {
                    code: 2,
                    message: "no such file or directory"
                }
            }
        }
    )
}
```

Example of new impl:

```rust
Custom {
    kind: InvalidData,
    error: Os {
        code: 2,
        kind: NotFound,
        message: "no such file or directory"
    }
}
```
bors added a commit that referenced this pull request Jan 15, 2018
Rollup of 10 pull requests

- Successful merges: #47120, #47126, #47277, #47330, #47368, #47372, #47414, #47417, #47432, #47443
- Failed merges: #47334
@bors bors merged commit 52e074e into rust-lang:master Jan 15, 2018
@clarfonthey clarfonthey deleted the io_error_debug branch May 5, 2018 04:33
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
S-waiting-on-author Status: This is awaiting some action (such as code changes or more information) from the author.
Projects
None yet
Development

Successfully merging this pull request may close these issues.

9 participants