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

Same message duplicated between source() and Display of serde_json::Error #991

Closed
dtolnay opened this issue Mar 5, 2023 · 0 comments · Fixed by #992
Closed

Same message duplicated between source() and Display of serde_json::Error #991

dtolnay opened this issue Mar 5, 2023 · 0 comments · Fixed by #992

Comments

@dtolnay
Copy link
Member

dtolnay commented Mar 5, 2023

// [dependencies]
// anyhow = "1"
// serde = "1"
// serde_json = "1"

use serde::de::Deserialize;
use std::error::Error;
use std::fmt::{self, Display};
use std::io::{self, Read};

struct Reader;

#[derive(Debug)]
struct MyError;

impl Error for MyError {
    fn source(&self) -> Option<&(dyn Error + 'static)> {
        Some(&std::sync::mpsc::RecvTimeoutError::Timeout)
    }
}

impl Display for MyError {
    fn fmt(&self, formatter: &mut fmt::Formatter) -> fmt::Result {
        formatter.write_str("bad read")
    }
}

impl Read for Reader {
    fn read(&mut self, _: &mut [u8]) -> io::Result<usize> {
        Err(io::Error::new(io::ErrorKind::TimedOut, MyError))
    }
}

fn main() -> anyhow::Result<()> {
    let reader = Reader;
    let mut de = serde_json::Deserializer::from_reader(reader);
    let _ = u8::deserialize(&mut de)?;
    Ok(())
}
Error: bad read

Caused by:
    0: bad read
    1: timed out waiting on channel

In general, std::error::Error impls are not supposed to duplicate the same content between their Display and source() implementation.

crapStone added a commit to Calciumdibromid/CaBr2 that referenced this issue Mar 6, 2023
This PR contains the following updates:

| Package | Type | Update | Change |
|---|---|---|---|
| [serde_json](https://github.com/serde-rs/json) | dependencies | patch | `1.0.93` -> `1.0.94` |

---

### Release Notes

<details>
<summary>serde-rs/json</summary>

### [`v1.0.94`](https://github.com/serde-rs/json/releases/tag/v1.0.94)

[Compare Source](serde-rs/json@v1.0.93...v1.0.94)

-   Fix message duplication between serde_json::Error's `Display` and `source()` ([#&#8203;991](serde-rs/json#991), [#&#8203;992](serde-rs/json#992))

</details>

---

### Configuration

📅 **Schedule**: Branch creation - At any time (no schedule defined), Automerge - At any time (no schedule defined).

🚦 **Automerge**: Disabled by config. Please merge this manually once you are satisfied.

♻ **Rebasing**: Whenever PR becomes conflicted, or you tick the rebase/retry checkbox.

🔕 **Ignore**: Close this PR and you won't be reminded about this update again.

---

 - [ ] <!-- rebase-check -->If you want to rebase/retry this PR, check this box

---

This PR has been generated by [Renovate Bot](https://github.com/renovatebot/renovate).
<!--renovate-debug:eyJjcmVhdGVkSW5WZXIiOiIzNC4xNTcuMCIsInVwZGF0ZWRJblZlciI6IjM0LjE1Ny4wIn0=-->

Co-authored-by: cabr2-bot <cabr2.help@gmail.com>
Co-authored-by: crapStone <crapstone01@gmail.com>
Reviewed-on: https://codeberg.org/Calciumdibromid/CaBr2/pulls/1807
Reviewed-by: crapStone <crapstone@noreply.codeberg.org>
Co-authored-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Co-committed-by: Calciumdibromid Bot <cabr2_bot@noreply.codeberg.org>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Development

Successfully merging a pull request may close this issue.

1 participant