Files
figcraft/crates/engine/src/error.rs
T
Trevor BrownandClaude Opus 5.5 bdf6ff9223 M8: after Crop is chosen in the image fill's menu, a drag on the image crops it, and no internal gesture message shows (#2307)
With the colour picker open on an image fill in Crop mode, a press on the layer closed the picker, and closing it committed the drag as a plain move: the whole layer moved instead of the picture inside it. The picker now treats a crop drag as its own control, as it does the open gradient's handles (#1852), so the press doesn't close it and the drag moves the crop.

A drag whose gesture something else committed under the held button went on calling the engine's preview, whose "no gesture in progress" error reached the canvas as a message. That error is now its own EngineError::NoGesture, which the canvas drops: the drag it belonged to is over, and it says nothing to the user.

Tests: crop_image_tests::crop_from_the_colour_picker_then_a_drag_on_the_image_moves_the_crop_not_the_layer (failed before: the crop didn't move) and a_drag_whose_gesture_was_committed_under_the_button_shows_no_message (failed before: "no gesture in progress").

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Model-Effort: Opus 5.5 drove and finished; Sonnet 5.5 wrote at medium (cut off by an API error)
2026-11-13 05:38:36 -05:00

56 lines
2.0 KiB
Rust

use super::NodeId;
#[derive(Debug, thiserror::Error)]
pub enum EngineError {
#[error("unknown command `{0}`")]
UnknownCommand(String),
#[error("command `{0}` is not available right now: {1}")]
Disabled(String, String),
#[error("invalid parameters for `{cmd}`: {msg}")]
BadParams { cmd: String, msg: String },
#[error("no open document")]
NoDocument,
#[error("no such node {0}")]
NoNode(NodeId),
#[error("{0}")]
Other(String),
/// A preview was asked for with no gesture open (something committed it under a held button).
/// Not for the user: the canvas drops it, as the drag it belonged to is over.
#[error("no gesture in progress")]
NoGesture,
/// A command run in the background sent a request to a server and runs again with the answer
/// ([`background`]); never returned to other callers.
#[error("waiting for the server")]
Waiting,
/// A bug: the command panicked. The document was rolled back.
#[error("internal error in `{cmd}`: {msg} (the document was left as it was before; please report this bug)")]
Internal { cmd: String, msg: String },
}
impl From<figcraft_doc::DocError> for EngineError {
fn from(e: figcraft_doc::DocError) -> Self {
match e {
figcraft_doc::DocError::NoNode(id) => EngineError::NoNode(id),
other => EngineError::Other(other.to_string()),
}
}
}
impl EngineError {
/// This error from step `step` of a batch, saying so in its message; the kind stays (errors
/// without a message stay as they are).
pub(crate) fn at_step(self, step: usize) -> Self {
match self {
EngineError::BadParams { cmd, msg } => EngineError::BadParams { cmd, msg: format!("step {step}: {msg}") },
EngineError::Other(msg) => EngineError::Other(format!("step {step}: {msg}")),
e => e,
}
}
}
pub type Result<T> = std::result::Result<T, EngineError>;
pub fn bad(cmd: &str, msg: impl Into<String>) -> EngineError {
EngineError::BadParams { cmd: cmd.to_string(), msg: msg.into() }
}