Skip to content

Better Debug impl for io::Error.#47120

Merged
bors merged 1 commit into
rust-lang:masterfrom
clarfonthey:io_error_debug
Jan 15, 2018
Merged

Better Debug impl for io::Error.#47120
bors merged 1 commit into
rust-lang:masterfrom
clarfonthey:io_error_debug

Conversation

@clarfonthey

@clarfonthey clarfonthey commented Jan 2, 2018

Copy link
Copy Markdown
Contributor

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
Copy Markdown
Contributor

r? @dtolnay

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

@dtolnay dtolnay left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

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

Thanks!

@dtolnay

dtolnay commented Jan 2, 2018

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jan 2, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit f058dce has been approved by dtolnay

@clarfonthey

Copy link
Copy Markdown
Contributor Author

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

@dtolnay

dtolnay commented Jan 2, 2018

Copy link
Copy Markdown
Member

@bors r+

@bors

bors commented Jan 2, 2018

Copy link
Copy Markdown
Collaborator

📌 Commit 418d050 has been approved by dtolnay

@frewsxcv

frewsxcv commented Jan 2, 2018

Copy link
Copy Markdown
Contributor

@bors rollup

@frewsxcv

frewsxcv commented Jan 2, 2018

Copy link
Copy Markdown
Contributor
[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
Comment thread src/libstd/io/error.rs Outdated

Copy link
Copy Markdown
Contributor

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
Copy Markdown
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
Copy Markdown
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

dtolnay commented Jan 3, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
Contributor Author

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

Comment thread src/libstd/io/error.rs Outdated

Copy link
Copy Markdown
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
Copy Markdown
Contributor Author

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

@dtolnay

dtolnay commented Jan 5, 2018

Copy link
Copy Markdown
Member

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
Copy Markdown
Member

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

@killercup

Copy link
Copy Markdown
Contributor

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

@bors r=dtolnay

@bors

bors commented Jan 14, 2018

Copy link
Copy Markdown
Collaborator

📌 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