scratch_test_model/
error.rs1use std::path::PathBuf;
2
3pub use crate::aux::JsonCtx;
4use crate::{
5 Id,
6 attrs::data::{ListKind, VariableKind},
7};
8
9pub use crate::aux::errors::{
10 AttributeContentError, AttributeParseError, BlockJsonStructureError, BlockKindError,
11 MandatoryAttrMissingError,
12};
13pub use crate::scopes::project_doc::NoValidBlockForId;
14pub use crate::scopes::target_blocks::BlockReferenceInvalid;
15
16#[allow(unused)]
17use crate::attrs::{List, Variable};
18
19#[derive(Debug, PartialEq, Eq, PartialOrd, Ord, thiserror::Error)]
27pub enum TargetDataError<Kind> {
28 #[error("expected object {{...}} for data entities of target")]
32 ExpectedObject,
33 #[error("at least one target data entry (id={0:?}) has unknown structure")]
35 AtLeastOneInvalid(Id),
36 #[error("SHOULD NEVER OCCUR")]
39 Phantom {
40 phantom: std::marker::PhantomData<Kind>,
41 delete: std::convert::Infallible,
42 },
43}
44
45#[derive(Debug, PartialEq, thiserror::Error)]
47pub enum BlockError<'a> {
48 #[error("missing block attr: {0}")]
56 MissingMandatoryAttr(&'static str),
57
58 #[error("block attr '{attr_name}' should have type '{expected_type}'")]
61 AttrType {
62 attr_name: &'static str,
63 expected_type: &'static str,
64 },
65
66 #[error("{0}")]
69 Kind(BlockKindError<'a>),
70}
71
72#[derive(Debug, thiserror::Error)]
78pub enum TargetBlocksError<'a> {
79 #[error("expected object {{...}} for blocks of target")]
81 ExpectedObject,
82 #[error("at least one target block (id={id:?}) has unknown structure (block-error={error})")]
84 AtLeastOneInvalid {
85 id: Id,
86 error: JsonCtx<'a, BlockError<'a>>,
87 },
88}
89
90#[derive(Debug, thiserror::Error, derive_more::From)]
92pub enum TargetError<'a> {
93 #[error("the attribute \"isStage\" of the target is missing")]
95 MissingIsStage,
96 #[error("the attribute \"name\" of the target is missing")]
98 MissingName,
99
100 #[error("error in target variables: {0}")]
102 TargetVar(JsonCtx<'a, TargetDataError<VariableKind>>),
103 #[error("error in target lists: {0}")]
105 TargetLis(JsonCtx<'a, TargetDataError<ListKind>>),
106 #[error("error in target blocks: {0}")]
108 TargetBlocks(TargetBlocksError<'a>),
109}
110
111#[derive(Debug, thiserror::Error, derive_more::From)]
117pub enum ModelError<'a> {
118 #[error("target error: {0}")]
120 Target(JsonCtx<'a, TargetError<'a>>),
121 #[error("The document doesn't contain a \"targets\" array: {0}")]
123 #[from(skip)]
124 NoTargetsArray(&'a serde_json::Value),
125}
126
127#[derive(Debug, thiserror::Error, derive_more::From)]
129pub enum ParseError<'a> {
130 #[error("model: {0}")]
131 Model(ModelError<'a>),
132 #[error("document: {0}")]
133 Doc(DocError),
134}
135
136#[derive(Debug, thiserror::Error, derive_more::From)]
138pub enum DocError {
139 #[error("stream or file was used that doesn't contain a document")]
140 NoDocument,
141 #[error("io error: {0}")]
142 #[from(skip)]
143 Io(#[from] Box<dyn std::error::Error>),
144 #[error("invalid json document: {0}")]
145 #[from(skip)]
146 Json(#[from] serde_json::Error),
147 #[error("file {0:?} read error: {1}")]
148 #[from(skip)]
149 FileRead(PathBuf, std::io::Error),
150}
151
152#[cfg(feature = "sb3")]
153impl From<zip::result::ZipError> for DocError {
154 fn from(value: zip::result::ZipError) -> Self {
155 Self::Io(value.into())
156 }
157}