Skip to content

#279 WP2: misuse becomes a compile error or a report with a fallback - #304

Merged
samitbasu merged 2 commits into
mainfrom
wp2-misuse
Nov 17, 2026
Merged

samitbasu merged 2 commits into
mainfrom
wp2-misuse

Conversation

@samitbasu

@samitbasu samitbasu commented Nov 17, 2026 •

Copy link
Copy Markdown
Owner

Part of #279
Fixes #283

No misuse check in the library panics any more, in any build. Where a type can express it, the misuse no longer compiles (each with a compile_fail doctest beside a passing one). Where the problem is data the library only sees during a frame, it is reported through the WP1 channel (report / Problem) and the library recovers.

Sites

Site Was Now
Command::on_error on a plain command (commands.rs) debug panic compile error: only PasteCommand has on_error
A command bound to a bare Esc or Enter (commands.rs) reported ReservedChord type: Chord::new returns None for them; in a const it is a compile error
Motion setters without .shown (overlay_chain.rs) debug_assert! compile error: shown() turns a Static chain into an Animated one, which alone has the setters
drag_handle on a node that is not a drag source (builder.rs) debug_assert! compile error: drag_source() returns a NodeHandle<…, DragSource>, which alone has drag_handle
Icon-only or empty button without a name (owned/button.rs) debug_assert! compile error: Face::Icon and Face::Empty hold the name
Button with an empty label and no name (data) debug_assert! report Unnamed
Unknown command id: menu item and button (owned/menu.rs, owned/button.rs) debug panic report UnknownCommand; the item is drawn disabled, labelled by the id; the button is added disabled
needs_identity on an anonymous node (Builder::node) debug_assert! report NeedsIdentity; the identity-needing classes are dropped (group_hover is kept)
A group that senses nothing (Builder::node) debug_assert! report GroupSensesNothing (new); the group senses hover
group_hover with no group above (draw.rs) debug_assert! report GroupHoverWithoutGroup; the look never shows
Overlay anchor or boundary node missing on the opening frame (pipeline.rs) debug panic + unreachable! report MissingAnchor at the declaration; the overlay is hidden (Detached) and dismissed, as release builds already did
focus_on_open twice in one overlay (overlay_input.rs) debug_assert! report FocusOnOpenTwice; the first marked node takes focus
Nav::Grid with Wrap::Around (overlay_chain.rs) debug_assert! compile error: Wrap is a payload of the linear navs only; Nav::Grid takes none and .wrap() is gone
drag_handle key not in the subtree, or naming a source (builder.rs) debug_assert! report DragHandle at the call; the whole source lifts
Table: too many rows, a short row, a cell past the columns (owned/table.rs, TODO(#279)) silent report TableShape (new); rows dropped / blanks kept / extra cell dropped, as before
Markdown parser: a cell or row outside a table, a block inside a table, a close with nothing open, an item outside a list (TODO(#279) ×4) silent the parser collects them in Parsed::malformed; Markdown::add reports each as MalformedMarkdown (new, on eggshell::misuse: it is the author's data, not an eggshell bug), one report per kind; the recovery is unchanged

Every converted should_panic test is now a test that asserts the report and, where there is one, the fallback through the real path (kittest harness or Headless).

Breaking changes

Command::paste returns a PasteCommand; on_error lives only there. Commands::add takes impl Into<Command<A>>, so call sites are unchanged.

// before
pub fn paste(title: &'static str, run: fn(&mut A, Paste, Via)) -> Command<A>
impl<A> Command<A> { pub fn on_error(self, hear: fn(&mut A, ClipboardError)) -> Self }
pub fn add<K: Key>(self, id: K, command: Command<A>) -> Self
// after
pub fn paste(title: &'static str, run: fn(&mut A, Paste, Via)) -> PasteCommand<A>
impl<A> PasteCommand<A> { pub fn on_error(..) -> Self; pub fn shortcut(..); pub fn enabled(..); pub fn in_text(..) }
impl<A> From<PasteCommand<A>> for Command<A>
pub fn add<K: Key>(self, id: K, command: impl Into<Command<A>>) -> Self

A shortcut is a Chord. Command::chord() still returns Option<KeyboardShortcut>.

// before
pub fn shortcut(self, shortcut: KeyboardShortcut) -> Self
.shortcut(KeyboardShortcut::new(Modifiers::COMMAND, Key::S))
// after
pub struct Chord(/* private */);
impl Chord { pub const fn new(modifiers: Modifiers, key: Key) -> Option<Self> }
impl From<Chord> for KeyboardShortcut
pub fn shortcut(self, shortcut: Chord) -> Self
.shortcut(const { Chord::new(Modifiers::COMMAND, Key::S).expect("not reserved") })

Problem: ReservedChord removed (unrepresentable now); GroupSensesNothing, Unnamed, TableShape and MalformedMarkdown added.

OverlayChain gains a motion state (defaulted, so existing type names still compile). shown can be called once.

// before
pub struct OverlayChain<'b, 'f, A, State>
pub fn shown(self, shown: Shown) -> Self               // and transition/exit_transition/easing/ease_*/entrance/on_exited on every chain
// after
pub struct OverlayChain<'b, 'f, A, State, Motion = Static>
pub struct Static; pub struct Animated;                 // in eggshell_ui::overlay
impl<..> OverlayChain<'b, 'f, A, State, Static> { pub fn shown(self, shown: Shown) -> OverlayChain<'b, 'f, A, State, Animated> }
impl<..> OverlayChain<'_, '_, A, State, Animated> { transition, exit_transition, easing, ease_*, entrance, on_exited }

NodeHandle gains a kind (defaulted). A trait implemented for NodeHandle<'_, 'f, A> now covers only AnyNode; eggshell-ui-shadcn's DragChip was made generic over the kind.

// before
pub struct NodeHandle<'b, 'f, A>
pub fn drag_source<T>(self, payload: T) -> Self
pub fn drag_handle<K: Key>(self, key: K) -> Self        // on every handle
// after
pub struct NodeHandle<'b, 'f, A, Kind = AnyNode>
pub struct AnyNode; pub struct DragSource;
pub fn drag_source<T>(self, payload: T) -> NodeHandle<'b, 'f, A, DragSource>
impl NodeHandle<'_, 'f, A, DragSource> { pub fn drag_handle<K: Key>(self, key: K) -> Self }

Face holds the name of a face without a label.

// before
pub enum Face { Label(String), Icon(Icon), Empty }
impl From<Icon> for Face
b.button("close", close).named("Close")
b.button("card", Face::Empty).named("Card")
// after
pub enum Face { Label(String), Icon(Icon, String), Empty(String) }
impl<S: Into<String>> From<(Icon, S)> for Face
b.button("close", (close, "Close"))
b.button("card", Face::Empty("Card".into()))

Wrap moves onto the linear navs; .wrap() is gone. Each nav keeps its old default: menus, submenus and listboxes went round unless told otherwise, the select stopped, a grid stops.

// before
pub enum Nav { None, Menu, Submenu, Listbox, Grid }
impl OverlayChain<..> { pub fn wrap(self, wrap: Wrap) -> Self }
.nav(Nav::Menu)
.nav(Nav::Listbox).wrap(Wrap::Stop)
.nav(Nav::Grid)
// after
pub enum Nav { None, Menu(Wrap), Submenu(Wrap), Listbox(Wrap), Grid }
.nav(Nav::Menu(Wrap::Around))
.nav(Nav::Listbox(Wrap::Stop))
.nav(Nav::Grid)

The code snippets in docs/overlays.md (lines 489, 502, 520, 534) are updated to the new form; the prose around them is not.

A virtual list stops at its ends: it takes Nav::Listbox(Wrap::Stop) (or Nav::None); Nav::Listbox(Wrap::Around) there is reported as UnsupportedNav, as other navs already were, and the list stops. Giving the virtual list a nav type of its own would make that unrepresentable too; left for a decision.

report stays #[doc(hidden)] and is not a stable API: it is pub only so eggshell-ui-extras can report through the same channel (as Builder::keyed_under).

Behaviour changes

  • Every report above runs in every build (all are cheap); before, most were debug-only panics and release builds went on silently.
  • An anonymous node with identity-needing classes no longer reaches the draw with a sense and no id: its sense, group, state variants (other than group_hover), transition and animate_layout are dropped.
  • A group that senses nothing now senses hover, so its group_hover children respond.
  • An unknown command's menu item is drawn (disabled, labelled by the id's Debug); before, release builds left the item out.
  • A misplaced drag handle no longer replaces the source's activator: the whole source lifts. Before, release builds set the handle even when it named a drag source.
  • A dropdown menu with an icon face is named by the face's name; before it was named only by .named.
  • Markdown problems are logged on eggshell::misuse as warnings.

Left alone

  • WP3 (taffy accessors), WP4 (index operations, pipeline.rs unreachable! on the base root), WP6 (Ui::shell()), WP7 (testing assertions), WP8 (lints).
  • TODO(#279) in draw.rs (text with links and no id: an internal invariant, likely WP4's Identified variant) and in testing.rs (PixelsPerPoint::new has no context: WP7).

Prose for the user

Not edited; these now describe behaviour that changed:

  • docs/dnd.md:11: a misplaced drag handle "panics in debug builds" (now reported, or a compile error for a non-source).
  • docs/overlays.md:195: a missing boundary node is a debug panic (now reported).
  • docs/overlays.md:215: a missing anchor on the opening frame is a debug panic (now reported).
  • docs/overlays.md:703: motion methods without shown are a debug panic (now a compile error).
  • docs/overlays.md:754: an unknown command id panics in a debug build (now a disabled, reported item).
  • docs/overlays.md:680 and :763: OverlayChain::wrap and Wrap::of(nav), both gone; a grid with Wrap::Around is now unrepresentable.
  • src/builder.rs ~126, Builder rustdoc: duplicate paths "panic" (WP1 made them a report).
  • I adjusted rustdoc that would otherwise be false (Nav variants, Wrap, focus_on_open, drag_handle, Menu::command, ButtonChain::command, Face, motion setters) minimally; reword as you like. New public items carry TODO(prose).

Likely conflicts with #300

src/commands.rs (Command/Commands::add), src/builder.rs (commands(), NodeHandle), crates/eggshell-ui-extras/src/markdown/mod.rs (Markdown::add), src/lib.rs exports, and smaller hunks in src/pipeline.rs and src/draw.rs.

cargo xtask ci: exit 0.

🤖 Generated with Claude Code

No misuse check in the library panics any more, in any build. Where a
type can say it, the misuse no longer compiles; where it is data the
library cannot see until a frame, it is reported through the WP1 channel
and the library recovers.

Compile errors (typestate or types):
- Command::paste returns a PasteCommand, the only kind with on_error.
- A command's shortcut is a Chord, whose constructor refuses a bare Esc
  or Enter; made in a const, the reserved chord is a compile error.
  Problem::ReservedChord goes, since the table can no longer hold one.
- OverlayChain gains a Motion state: shown() turns Static into Animated,
  and only an Animated chain has the motion setters.
- NodeHandle gains a Kind: drag_source() returns a DragSource handle,
  the only kind with drag_handle.
- An icon-only or empty button Face holds its accessible name.

Report and fall back:
- Unknown command id: the menu item (or button) is disabled; reported.
- Classes that need an identity on an anonymous node are dropped; a
  group that senses nothing senses hover; group_hover without a group
  never shows. Each is reported.
- A missing overlay anchor or boundary is reported; the overlay is still
  hidden and dismissed as before.
- focus_on_open twice: the first marked node wins; reported.
- Nav::Grid told to Wrap::Around stops; reported as UnsupportedNav (the
  typestate shape is left for a decision).
- A misplaced drag handle is reported and the whole source lifts.
- A button with an empty label and no name is reported.
- A table row of the wrong cell count, or too many rows, is reported.
- The Markdown parser collects what it recovered from and the widget
  reports it; report() is public for that.

Breaking changes: Command::paste/on_error, Command::shortcut,
Commands::add, Problem variants, OverlayChain and NodeHandle type
parameters, Face::Icon/Face::Empty and From<Icon> for Face.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

Decisions (user, 2026-11-17):

  • Breaks 1–6 are approved.
  • report() becomes #[doc(hidden)] (for eggshell-ui-extras), not public API.
  • Markdown's malformed input gets its own Problem variant on the misuse target, not Internal.
  • Nav wrap is option 1: Nav::Menu(Wrap), Nav::Submenu(Wrap) and Nav::Listbox(Wrap); Nav::Grid takes none.

Review follow-ups on #304:
- Nav::Menu, Nav::Submenu and Nav::Listbox carry their Wrap and
  Nav::Grid takes none, so a grid that wraps around cannot be written.
  OverlayChain::wrap, Wrap::of, Behavior::wrap and the grid's
  UnsupportedNav report path are gone. Each nav keeps its old default:
  menus, submenus and listboxes go round, the select stops. A virtual
  list takes Nav::Listbox(Wrap::Stop); Around there is reported as
  UnsupportedNav and the list stops.
- Malformed Markdown is reported as a new Problem::MalformedMarkdown on
  eggshell::misuse, one report per kind, not as Problem::Internal: it is
  the author's data, not an eggshell bug.
- report() is #[doc(hidden)] and not a stable API; it is pub only for
  eggshell-ui-extras.

Breaking: Nav's Menu/Submenu/Listbox variants take a Wrap; OverlayChain
loses wrap().

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01PWiKKe8zfqGfVMCSC5L3up
@samitbasu

Copy link
Copy Markdown
Owner Author

Gate (my run on 36803bd with current main): cargo xtask ci (with fuzz) exits 0. The breaks were approved by the user (2026-11-17). Merging (the user authorised merges).

@samitbasu
samitbasu merged commit 6788d93 into main Nov 17, 2026
4 checks passed
samitbasu added a commit that referenced this pull request Nov 17, 2026
WP2 (#304) made a shortcut a `Chord` and built `Command` around a private
`Binding`, with `PasteCommand` for the clipboard. The mount lifts whole
command tables, so the new shapes need no change in its sink; the docs
example and the mount tests take `Chord` for their shortcuts.

Two new tests prove a paste command declared inside a mount gets the menu
click (a read) and the chord (the event) through the lens, and hears a
failed read there. Dropping the mount's table forwarding fails the chord
test; the baseline passes.

Part of #251

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01LesfK54UWq1haPSEr9X22o
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

#279 WP2: misuse checks become typestate or report + fallback

1 participant