Files
vectorcraft/crates/engine/src/error.rs
T
dotCooCoo 82e3d6dac3 Plug-ins: the web build checks plug-ins and runs filters in a Web Worker
On the web, a plug-in being installed ran its start function and
vc_manifest on the page, and a filter ran on the page for its whole
budget, so a slow or looping module froze the tab for up to a minute
(five for a heavy filter), and Cancel could not stop it.

- A second wasm, apps/vectorcraft-plugin-worker, is built by Trunk as a
  worker (data-type="worker" with data-loader-shim in index.html). The
  page starts one worker for each check and each run, and terminates it
  on Cancel, when the document or the plug-in changes, and 5 s past the
  run's time budget, also while a dialog is open. Each worker's inbox
  holds its latest progress report and at most 8 other messages.
- crates/plugins/src/worker.rs holds the messages and the worker's
  side. Runs can pause at each vc_call (Plugin::begin_run and
  resume_run), which the desktop's synchronous calls now use too.
- Install Plug-in... and File > Open check a module in a worker first;
  the page then loads it with Plugin::load_checked, which runs none of
  its code.
- A filter that calls commands sends each call to the page. The session
  holds the run's undo step open and refuses other edits with "a
  plug-in is running: cancel it or wait for it to finish" until the run
  ends; the progress window shows at once with Cancel only.
- On the web every filter and plug-in command started from the menus
  or their dialogs runs in a worker, and the dialogs have no Preview.
  A plug-in command applies as itself, one undo step named after it.
  Commands that automation runs directly still run where they are
  called and return their result.
- packaging/web: the worker files carry no hash, so the sample cache
  rules make only the hashed app files immutable.
2026-11-22 10:15:28 -08:00

61 lines
2.4 KiB
Rust

use super::{NodeId, cancel};
/// The text of [`EngineError::Busy`], which ends every error a frontend reports for it.
pub const SCRIPT_BUSY: &str = "a script is running: stop it or wait for it to finish";
/// The text of [`EngineError::PluginBusy`].
pub const PLUGIN_BUSY: &str = "a plug-in is running: cancel it or wait for it to finish";
/// Stable prefix for a save refused by the filesystem: choose another destination.
pub const READ_ONLY_LOCATION: &str = "READ_ONLY_LOCATION";
#[derive(Debug, thiserror::Error)]
pub enum EngineError {
#[error("unknown command `{0}`")]
UnknownCommand(String),
/// An unknown command id, with the command id it most likely misspells.
#[error("unknown command `{0}`; did you mean `{1}`?")]
UnknownCommandNear(String, 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 active document")]
NoDocument,
#[error("no such object {0}")]
NoNode(NodeId),
#[error("{0}")]
Other(String),
/// The save's terminal filesystem error refuses writes here. The reason keeps the path and
/// system message. This never means an automation-root refusal or a recovery-copy failure.
#[error("{code}: {0}", code = READ_ONLY_LOCATION)]
ReadOnlyLocation(String),
/// The caller asked for the command to stop ([`cancel`]). It changed nothing.
#[error("cancelled; nothing was changed")]
Cancelled,
/// A running script holds the documents until it ends. Nothing was changed.
#[error("{}", SCRIPT_BUSY)]
Busy,
/// A plug-in run that calls commands holds the documents until it ends
/// ([`crate::cmd::plugin::FilterRun::begin_calls`]). Nothing was changed.
#[error("{}", PLUGIN_BUSY)]
PluginBusy,
/// A bug: the command panicked. The document was rolled back to its state before the command.
#[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<cancel::Cancelled> for EngineError {
fn from(_: cancel::Cancelled) -> Self {
EngineError::Cancelled
}
}
impl From<vectorcraft_doc::DocError> for EngineError {
fn from(e: vectorcraft_doc::DocError) -> Self {
EngineError::Other(e.to_string())
}
}
pub type Result<T> = std::result::Result<T, EngineError>;