1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
//! Error handling for lib3mf-core.
//!
//! This module defines the error types returned by all fallible operations in the library.
//!
//! ## Design Philosophy
//!
//! The library follows a strict **no-panic** policy:
//!
//! - All errors are returned as `Result<T, Lib3mfError>`, never panicked
//! - Invalid user input (malformed 3MF files, bad parameters) produces errors, not panics
//! - Internal consistency violations are also returned as errors (via `InvalidStructure`)
//!
//! This makes the library safe to use in production environments where panics are unacceptable.
//!
//! ## Error Types
//!
//! [`Lib3mfError`] is the main error enum, with variants covering different failure modes:
//!
//! - **Io**: File system errors, network errors, ZIP reading failures
//! - **Validation**: Model failed validation checks (see [`crate::validation`])
//! - **ResourceNotFound**: Referenced resource ID doesn't exist in the model
//! - **InvalidStructure**: Malformed XML, missing required elements, spec violations
//! - **EncryptionError**: Cryptographic operations failed (wrong key, tampered data)
//! - **FeatureNotEnabled**: Operation requires a cargo feature that wasn't enabled
//!
//! ## Usage
//!
//! The [`Result`] type alias is provided for convenience:
//!
//! ```
//! use lib3mf_core::error::{Lib3mfError, Result};
//!
//! fn parse_something() -> Result<String> {
//! // Use the ? operator to propagate errors
//! Ok("success".to_string())
//! }
//! ```
//!
//! ## Error Context
//!
//! Most error variants include a `String` message with context about what failed:
//!
//! ```
//! use lib3mf_core::error::Lib3mfError;
//!
//! let error = Lib3mfError::InvalidStructure(
//! "Missing required 'unit' attribute on <model> element".to_string()
//! );
//!
//! // Error messages are human-readable
//! assert_eq!(
//! error.to_string(),
//! "Invalid 3MF structure: Missing required 'unit' attribute on <model> element"
//! );
//! ```
use Error;
/// The main error type for all fallible operations in lib3mf-core.
/// Convenience type alias for `Result<T, Lib3mfError>`.
pub type Result<T> = Result;