Skip to content

fix(ui-egui): #1046 decide on typed error kinds, not error message text - #1132

Merged
echelon merged 3 commits into
storytold:mainfrom
THEtheChad:fix/typed-error-kinds
Oct 14, 2026
Merged

echelon merged 3 commits into
storytold:mainfrom
THEtheChad:fix/typed-error-kinds

Conversation

@THEtheChad

Copy link
Copy Markdown
Contributor

What and why

The interface decided several things by reading an error's English text: whether to offer the face detector or SAM 3 download, and whether a SAM 3 download, a Lightroom inspect/import or an Apple Photos import was cancelled or failed. A reworded or translated message silently changes what the app does, and the Lightroom check already misreported real failures whose text contains "cancelled" (for example a catalog path) as cancels. #1046 has the full evidence.

This PR adds a typed signal next to the message wherever the UI decides. It keeps String messages and the JSON command boundary as they are.

Engine

  • EngineError::Cancelled(String) and EngineError::ModelMissing { model: AiModel, msg } (AiModel::{FaceDetector, Sam3}), plus EngineError::kind() -> ErrorKind, a Copy enum with one value per variant (crates/engine/src/errors.rs).
  • Produced at the source:
    • face_detect::detector returns NoDetector { NotInstalled, Unusable(String) }.
    • Segmenter::require_model() returns ModelMissing(Sam3); model_dir() stays as its string form.
    • AI mask commands check the model first, so both the waiting path (CLI/MCP) and the background path (app) report the kind.
    • The Lightroom job returns Cancelled when its cancel flag is set.
  • Error text is byte-identical to before, including the existing "invalid parameters for faces.detect: …" and "invalid parameters for library.importLightroom: Lightroom import cancelled" prefixes. Control channel and MCP clients see the same error strings, and tests assert this. Dropping those misleading prefixes is a separate wording decision for maintainers.
  • Background results that already cross the wire as JSON get additive fields:
    • segment.model.status → download.cancelled (set from fetch::DownloadError::Cancelled).
    • An Apple Photos import outcome gets cancelled: true next to skipped.
    • No existing field changes.

UI

  • LightcraftApp::run_typed(id, params) -> Result<Value, CommandError { message, kind }>. run is now run_typed(..).map_err(|e| e.message), so its 300+ callers are untouched.
  • Decisions now read kinds and flags:
    • The faces.detect offer and ai_error decide on ModelMissing.
    • The SAM 3 download toast (sam_download_ended) and the Apple Photos note decide on cancelled.
    • A Lightroom inspect/import decides on its own cancel flag only, because the worker stops only for that flag.
  • No behaviour-bearing match on error text is left in ui-egui, apps or mcp. A grep of non-test .contains( / starts_with( turns up only tests.

Docs

  • docs/ai-masks.md and docs/apple-photos.md describe the new cancelled flags, and docs/mcp.md describes the Apple Photos one.
  • docs/localization-parity.md notes that the shared "translatable lower-layer errors" work no longer changes behaviour. Last updated and revision history are bumped.
  • No parity or gap row changes: this is robustness, not a feature.

Tests

The new tests fail on the old string-matching logic. I checked this by putting the old .contains/starts_with checks back into the new code: 4 of the 5 UI tests failed.

  • Engine:
    • errors::tests::the_kind_does_not_depend_on_the_message
    • tests_face_models::detect_without_the_model_says_where_to_get_it: missing → ModelMissing(FaceDetector); unusable → BadParams, even though its text also says "Settings > Faces"; text unchanged.
    • tests_segment::a_missing_model_is_model_missing_by_kind: background and waiting paths.
    • tests_segment download tests assert cancelled.
    • lightroom_job::tests::a_cancelled_read_is_cancelled_by_kind: text unchanged.
    • apple_photos outcome test.
  • UI:
    • tests_error_kinds::*: a translated message with the right kind still offers the model; a message that starts with NOT_INSTALLED but has the wrong kind does not.
    • lightroom_import::tests::lightroom_cancel_is_the_flag_not_the_words
    • export_task::tests::apple_photos_outcomes_read_well
  • The existing detect_faces_without_the_detector_offers_the_download… and tests_masking tests pass, with and without --features lightcraft-engine/sam.
  • cargo xtask ci: all 8 steps passed (fmt, clippy, heif, test, parity, layers, assets, wasm).

Left out on purpose

Overlap

  • A parallel branch (perf/command-overhead, per-command UI-thread work) also edits crates/engine/src/cmd/face_detect.rs and crates/engine/src/lib.rs. This PR touches lib.rs in 9 lines only (module, re-export, two variants) and stands alone on main.
  • LR-LIB-FOLDER: a refused command says why #777 also edits LightcraftApp::run. The changes are compatible, but whichever lands second needs a small rebase.

Refs #1046 (the engine-internal matches and the wire code remain open)

🤖 Generated with Claude Code

THEtheChad and others added 3 commits October 11, 2026 16:26
… missing models

EngineError gains Cancelled and ModelMissing { model: AiModel } and a
kind() -> ErrorKind, so frontends decide on what an error is rather than
on its words. The face detector, SAM 3 model checks and the Lightroom
job produce them at the source; the error text is unchanged, so control
channel and MCP clients see the same `error` strings.

Background results that cross the wire as JSON get an additive flag
instead: SAM 3 download status `cancelled`, Apple Photos import outcome
`cancelled: true` next to `skipped`.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…sage text

LightcraftApp::run_typed keeps the engine's ErrorKind in a CommandError;
run() is run_typed(..).map_err(|e| e.message), so its callers are
untouched. The face detector offer and the SAM 3 download dialog decide
on ModelMissing, the SAM 3 download toast and the Apple Photos note on
the `cancelled` flag, and a Lightroom inspect/import on its own cancel
flag only, so a failure that mentions "cancelled" is still a failure.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
…ides on error kinds

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@echelon

echelon commented Oct 14, 2026

Copy link
Copy Markdown
Member

Thank you @THEtheChad! This landed on main in integration batch 35 (#1682). Your cancel test now unpacks the four-part fake import that is on main.

If you haven't already, please join our Discord: https://discord.gg/artcraft. We'd love to have you there.

Omninovas pushed a commit to Omninovas/lightcraft that referenced this pull request Oct 14, 2026
…storytold#1412 left

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
bogusyogi pushed a commit to Orthic-Labs/ember that referenced this pull request Oct 14, 2026
…storytold#1412 left

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
(cherry picked from commit a5989d6)
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.

2 participants