ECSError Display implementation prints double messages and unwraps on write failure #671

Open
opened 2026-07-05 03:22:40 +02:00 by Hermes · 0 comments
Collaborator

Severity: 🟡 Medium

File: Crates/ecs/src/error.rs:11-22

Bug #1 — Double-printed error messages:
The Display implementation prints the formatted message AND then falls through to writeln!(f, "{self:?}") which prints the Debug representation. Every error message is printed twice with different formatting.

impl Display for ECSError {
    fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
        match self {
            ECSError::InvalidEntity(entity) => {
                writeln!(f, "Invalid Entity ...").unwrap()  // first message
            },
            ECSError::ComponentStoreNotExisting => {
                let _ = writeln!(f, "...");  // first message
            }
        }
        writeln!(f, "{self:?}")  // falls through to Debug — second message!
    }
}

Bug #2 — Inconsistent error handling:
The InvalidEntity branch uses .unwrap() on the writeln!() result, which will panic if the formatter encounters an error (e.g., broken pipe). The ComponentStoreNotExisting branch correctly uses let _ =.

Fixes:

  1. Remove the trailing writeln!(f, "{self:?}") or put it in an else.
  2. Use let _ = consistently instead of .unwrap().

@SakulFlee

**Severity:** 🟡 Medium **File:** `Crates/ecs/src/error.rs:11-22` **Bug #1 — Double-printed error messages:** The `Display` implementation prints the formatted message AND then falls through to `writeln!(f, "{self:?}")` which prints the Debug representation. Every error message is printed twice with different formatting. ```rust impl Display for ECSError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { ECSError::InvalidEntity(entity) => { writeln!(f, "Invalid Entity ...").unwrap() // first message }, ECSError::ComponentStoreNotExisting => { let _ = writeln!(f, "..."); // first message } } writeln!(f, "{self:?}") // falls through to Debug — second message! } } ``` **Bug #2 — Inconsistent error handling:** The `InvalidEntity` branch uses `.unwrap()` on the `writeln!()` result, which will **panic** if the formatter encounters an error (e.g., broken pipe). The `ComponentStoreNotExisting` branch correctly uses `let _ =`. **Fixes:** 1. Remove the trailing `writeln!(f, "{self:?}")` or put it in an `else`. 2. Use `let _ =` consistently instead of `.unwrap()`. @SakulFlee
Sign in to join this conversation.
No milestone
No project
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
SakulFlee/Orbital#671
No description provided.