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
use wick_packet::Entity;

use super::executor::error::ExecutionError;
use super::program::validator::error::{OperationInvalid, ValidationError};

#[derive(thiserror::Error, Debug)]
pub enum Error {
  #[error(transparent)]
  ExecutionError(#[from] ExecutionError),
  #[error("{}", .0.iter().map(|e|e.to_string()).collect::<Vec<_>>().join(", "))]
  ValidationError(Vec<OperationInvalid>),
  #[error("Early error: {:?}", .0)]
  EarlyError(ValidationError),
  #[error("Could not find operation '{}' ({0}). Known operations are: {}",.0.operation_id(), .1.join(", "))]
  OpNotFound(Entity, Vec<String>),
  #[error("Could not find target '{}' ({0}). Namespaces handled by this resource are: {}", .0.operation_id(), .1.join(", "))]
  TargetNotFound(Entity, Vec<String>),
  #[error("Error shutting down component: {0}")]
  ComponentShutdown(String),
  #[error("Shutdown failed: {0}")]
  Shutdown(String),
  #[error("Namespace '{0}' already exists, can not overwrite")]
  DuplicateNamespace(String),
}

#[derive(thiserror::Error, Debug, Clone, PartialEq, Eq)]
pub enum StateError {
  #[error("Payload for port '{0}' missing from input stream")]
  PayloadMissing(String),
  #[error(
    "Could not find port named '{0}'. This can result from providing more input than a schematic has ports for."
  )]
  MissingPortName(String),
  #[error("Attempted to access nonexistant component '{0}'")]
  MissingComponent(String),
  #[error("Tried to decrement pending counter for non-existent or zero ID.")]
  TooManyComplete,
}

impl From<Vec<OperationInvalid>> for Error {
  fn from(v: Vec<OperationInvalid>) -> Self {
    Error::ValidationError(v)
  }
}