forked from 1b-agent/opencadstudio-upstream
Add the typed document facade and plugin IPC adapter. Prepare bulk edits before mutation, preserve undo and dirty state, keep profile elevations, validate numeric inputs and session bindings, and generate Python constructors with typed results. Reuse existing entity transforms and profile conversion. Compute mass properties and closed-surface bounds in cadkernel; pin its main revision 6a5e6fc2822f6af6b2611cd605b44437b35158f0. Keep plugin API metadata at version 6. Validation: 646 native application tests, 597 kernel tests, 12 document API tests, 91 plugin API tests, 3 Python tests, default/IPC feature builds and wasm32 check passed.
69 lines
2.2 KiB
Rust
69 lines
2.2 KiB
Rust
//! Structured error model. Serializable so IPC returns the
|
|
//! same error the in-process executor produced.
|
|
|
|
use serde::{Deserialize, Serialize};
|
|
use thiserror::Error;
|
|
|
|
use crate::id::ObjectId;
|
|
|
|
/// Which kind of kernel failure occurred (a mapped `cadkernel` `Snag`).
|
|
#[derive(Debug, Clone, Copy, PartialEq, Eq, Serialize, Deserialize)]
|
|
pub enum GeometryErrorKind {
|
|
/// The operation produced an empty / degenerate body.
|
|
Empty,
|
|
/// Boolean refused (coincident geometry, unsupported cut, …).
|
|
BooleanFailed,
|
|
/// Invalid input to a kernel constructor (e.g. non-positive radius).
|
|
InvalidInput,
|
|
/// ACIS lift/parse/lower failed.
|
|
Acis,
|
|
/// Any other kernel error (message carries detail).
|
|
Other,
|
|
}
|
|
|
|
/// The single error type for the whole API. `commit`/ops return
|
|
/// `Result<_, ApiError>`; on a failed op nothing is applied and no undo step is
|
|
/// recorded (per-op atomicity).
|
|
#[derive(Error, Debug, Clone, PartialEq, Serialize, Deserialize)]
|
|
pub enum ApiError {
|
|
/// Input failed validation before any mutation (names the op + reason).
|
|
#[error("validation failed on {op}: {reason}")]
|
|
Validation { op: String, reason: String },
|
|
|
|
/// The geometry kernel reported a failure (a mapped `Snag`).
|
|
#[error("geometry kernel: {kind:?}: {msg}")]
|
|
Geometry {
|
|
kind: GeometryErrorKind,
|
|
msg: String,
|
|
},
|
|
|
|
/// An `ObjectId` does not resolve to a live entity (stale/deleted/never existed).
|
|
#[error("unknown ObjectId {0:?}")]
|
|
UnknownId(ObjectId),
|
|
|
|
/// The requested capability is not supported (e.g. over-cap bulk op, unimplemented family).
|
|
#[error("unsupported capability: {0}")]
|
|
Unsupported(String),
|
|
|
|
/// The transport (IPC / channel) failed — disconnected, oversized, timeout.
|
|
#[error("transport: {0}")]
|
|
Transport(String),
|
|
}
|
|
|
|
pub type ApiResult<T> = Result<T, ApiError>;
|
|
|
|
impl ApiError {
|
|
pub fn validation(op: &'static str, reason: impl Into<String>) -> Self {
|
|
ApiError::Validation {
|
|
op: op.to_string(),
|
|
reason: reason.into(),
|
|
}
|
|
}
|
|
pub fn geometry(kind: GeometryErrorKind, msg: impl Into<String>) -> Self {
|
|
ApiError::Geometry {
|
|
kind,
|
|
msg: msg.into(),
|
|
}
|
|
}
|
|
}
|