Files
lightcraft/crates/ui-egui/src/command_error.rs
T
Chad ElliottandClaude Opus 5.5 b3fcb77922 fix(ui-egui): #1046 decide on error kinds and flags, not message 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>
2026-10-11 16:26:04 -05:00

43 lines
1.1 KiB
Rust

//! A refused or failed command as the UI handles it (#1046): the message for people, and what kind of
//! error it is for code that decides on it. Decide on [`CommandError::kind`], never on the message:
//! messages get reworded and will be translated.
use lightcraft_engine::{EngineError, ErrorKind};
#[derive(Clone, Debug, PartialEq, Eq)]
pub struct CommandError {
pub message: String,
pub kind: ErrorKind,
}
impl std::fmt::Display for CommandError {
fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
f.write_str(&self.message)
}
}
/// An error the UI raised itself (its own commands, dialogs): [`ErrorKind::Other`].
impl From<String> for CommandError {
fn from(message: String) -> Self {
Self { message, kind: ErrorKind::Other }
}
}
impl From<&str> for CommandError {
fn from(message: &str) -> Self {
message.to_string().into()
}
}
impl From<EngineError> for CommandError {
fn from(e: EngineError) -> Self {
Self { kind: e.kind(), message: e.to_string() }
}
}
impl From<CommandError> for String {
fn from(e: CommandError) -> Self {
e.message
}
}