Skip to content

No panics in the library, in any build (audit, error channel, CI enforcement) #279

Closed
9 of 9 issues completed

Description

@samitbasu

Decided (user, 2026-11-16): panics in the library are unacceptable in every build, debug included. This supersedes the earlier debug-panic-on-misuse pattern (duplicate keys, a table's wrong cell count, splitter ranges, unknown command ids, Ui::shell() outside a draw, and so on).

Approach:

  1. Audit: inventory every panic site in library code (src/, crates/*/src; tests and xtask exempt): explicit (panic!, unwrap, expect, unreachable!, assert!, debug_assert!) and implicit (slice/array indexing, clamp on computed bounds, integer division and overflow, RefCell and Mutex borrows and poisoning, Option and Result unwraps in disguise). Classify each one:
    • (A) reachable from end-user input or data;
    • (B) API misuse by the app;
    • (C) an internal invariant.
  2. The replacement for each class:
    • A: handle it (clamp safely, skip, or recover).
    • B: make it unrepresentable (typestate or types) where possible; otherwise report it through one library error channel and use a safe fallback.
    • C: restructure so the invariant holds by construction, or recover silently plus report.
  3. One error channel: a single reporting path for misuse, decided once. For example: once per (context, site) to stderr or log, surfaced in the F12 debug overlay, and queryable in tests so they can assert on misuse without a panic.
  4. Enforcement in cargo xtask ci: clippy lints over library code (clippy::panic, unwrap_used, expect_used, unreachable, indexing_slicing, panic_in_result_fn, plus a check for assert!/debug_assert!), allowed in tests.

Existing "debug panic" behaviour in merged and open PRs gets converted. Follow-ups are #278 (shell() still panics outside a draw) and the misuse checks across the library.

Sub-issues

Sub-issues

9 of 9 Issues completed
Loading 9 sub-issues

Activity

  1. added
    v0.1
    on Nov 16, 2026
  2. samitbasu commented on Nov 16, 2026

    @samitbasu
    OwnerAuthor

    Policy for open PRs (2026-11-16): a PR must not add panic sites. Anything it introduces is converted before it merges. Patterns already on main are converted in this issue's sweep. In progress: #264, #268 (wordy-guy) and #271, #275, #267, #260 (blocky). #271's T1 cell-count debug panic becomes "drop extras, blank gaps, report".

  3. samitbasu commented on Nov 16, 2026

    @samitbasu
    OwnerAuthor

    Audit (main at 5fbc2c2, library code only; tests, examples, benches and xtask excluded)

    Explicit sites (115):

    • A, reachable from data or input (4): duplicate or colliding keys from data (key.rs:274, :276), an overlay anchored to a vanished node (pipeline.rs:660), two focus_on_open (overlay_input.rs:650).
    • B, app misuse (21): command validation, an unknown command, a missing style entry, layout and key clashes, Wrap::Around on Grid, motion without shown, needs_identity, the drag-handle checks, Ui::shell() outside a draw, and others.
    • C, internal invariants (79): 49 taffy-tree .expects and 30 structural.
    • T, test support (11).

    Implicit sites:

    • A (5): clamp with a reversed or NaN app range (number.rs:112, stepper.rs:385), the tooltip arrow clamp on a NaN rect (tooltip.rs:519), Duration overflow (transition.rs:88, tooltip.rs:387), and egui's own NaN debug asserts reachable through NaN layout.
    • C: about 205 index operations, all into per-frame vectors the library builds itself.

    No unwrap, todo, RefCell or NonZero; the Mutex locks already recover from poisoning.

    Work packages

    • WP1, the error channel: src/report.rs Problem enum, report(ctx, problem, subject, msg) deduplicated per (problem, call site, subject), sent to log (eggshell::misuse warn, eggshell::internal error), shown in the F12 overlay, with testing::reports/assert_reported/assert_no_reports.
    • WP2, misuse checks (25): typestate where possible (PasteCommand, a Chord newtype, a Nav::Grid without Wrap, motion only after shown, drag_handle only on a drag source); otherwise report and fall back.
    • WP3, taffy access (53): a LayoutTree wrapper whose accessors can't fail.
    • WP4, pipeline/draw structure: an Identified node variant, split root declarations, and a Nodes arena replacing about 205 index operations.
    • WP5, numbers, geometry and time: a ValueRange newtype, one NaN-total clamp helper, non-finite lengths rejected at the Tw boundary, try_from_secs.
    • WP6, the shell guard (A layout drawn inside another's draw closure removes the outer drawing shell; the outer layout's next owned button panics #278): decision pending.
    • WP7, test support: exempt the deliberate test assertions, and make Placed::overlay and Timeline::frame return Option.
    • WP8, lints: a crate-level deny of panic, unwrap_used, expect_used, unreachable, indexing_slicing (as a ratchet with module-level #[expect]), string_slice and others, with clippy.toml disallowing assert!/debug_assert!, f32::clamp, panicking Duration constructors and Mutex::lock.
  4. samitbasu commented on Nov 16, 2026

    @samitbasu
    OwnerAuthor

    Decided (user, 2026-11-16):

    • WP1: the error channel as designed (log targets eggshell::misuse/eggshell::internal, the F12 overlay list, and testing::reports/assert_reported/assert_no_reports).
    • Costly checks (duplicate-key detection, cross-layout key claims): debug builds only, report-only and never panic. Cheap checks run in every build.
    • WP7: the testing module's assertion helpers are exempt (explicit lint expect with a reason). Anything on the draw path stays panic-free.
    • WP6 (the shell API): pending.
  5. samitbasu commented on Nov 16, 2026

    @samitbasu
    OwnerAuthor

    WP6 decided (user, 2026-11-16): option B. ui.shell() is removed and ui.try_shell() -> Option<Shell> is the only form, keeping the context slot with #278's stack-restoring guard (it works inside egui's nested Ui scopes). NodeUi::node_id() and related accessors also become non-panicking. eggshell's own walk holds the shell directly instead of looking it up through Ui.

  6. 4 remaining items

  7. samitbasu commented on Nov 17, 2026

    @samitbasu
    OwnerAuthor

    Complete (2026-11-17). All eight work packages have merged:

    The three library crates now deny panic, unwrap, expect, unreachable, todo, unimplemented, indexing and string slicing, assert!/debug_assert!, clamp, the panicking Duration constructors and Mutex::lock, outside tests. A contributor exempts a site with #[expect(lint, reason = ..)] at the narrowest scope. Tag v0.1.0-m8.32.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    v0.1

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions