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

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

#[derive(thiserror::Error, Debug)]
#[non_exhaustive]
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 component '{}' ({0}). Namespaces handled by this resource are: {}", .0.component_id(), .1.join(", "))]
  TargetNotFound(Entity, Vec<String>),

  #[error("Can not invoke non-operation entity: {0}")]
  InvalidEntity(Entity),

  #[error("Error shutting down component: {0}")]
  ComponentShutdown(String),

  #[error("Shutdown failed: {0}")]
  Shutdown(String),

  #[error("Event loop panicked: {0}")]
  EventLoopPanic(String),

  #[error("Shutdown timed out")]
  ShutdownTimeout,

  #[error("Namespace '{0}' already exists, can not overwrite")]
  DuplicateNamespace(String),

  #[error(transparent)]
  OperationInit(#[from] OpInitError),

  #[error("Interpreter can only expose one component at a time, found multiple: {}", .0.join(", "))]
  ExposedLimit(Vec<String>),

  #[error("Could not render operation configuration: {0}")]
  Configuration(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("Attempted to start an instance ('{0}') more than once")]
  InvocationMissing(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)
  }
}