wick_runtime/
error.rs

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
89
90
91
92
93
94
95
96
97
98
99
use std::convert::Infallible;

use thiserror::Error;
use wick_config::config::{ComponentKind, TriggerKind};
use wick_packet::Entity;

pub use crate::components::error::ComponentError;
pub use crate::runtime::scope::error::ScopeError;

#[derive(Debug, Clone, Copy)]
#[non_exhaustive]
pub enum Context {
  Trigger,
  TriggerKind(TriggerKind),
  Import,
  Resource,
  Component,
  ComponentKind(ComponentKind),
}

impl std::fmt::Display for Context {
  fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result {
    match self {
      Context::Trigger => write!(f, "trigger"),
      Context::TriggerKind(kind) => write!(f, "trigger {}", kind),
      Context::Import => write!(f, "import"),
      Context::Resource => write!(f, "resource"),
      Context::Component => write!(f, "component"),
      Context::ComponentKind(kind) => write!(f, "component {}", kind),
    }
  }
}

impl From<TriggerKind> for Context {
  fn from(kind: TriggerKind) -> Self {
    Context::TriggerKind(kind)
  }
}

impl From<ComponentKind> for Context {
  fn from(kind: ComponentKind) -> Self {
    Context::ComponentKind(kind)
  }
}

#[derive(Error, Debug)]
#[non_exhaustive]
pub enum RuntimeError {
  #[error("Invalid {0} configuration, expected configuration for {0}")]
  TriggerKind(Context, TriggerKind),

  #[error("Invalid {0} configuration: {1}")]
  InvalidConfig(Context, String),

  #[error("invalid target '{0}'")]
  InvalidTarget(Entity),

  #[error("{0} requested resource '{1}' which could not be found")]
  ResourceNotFound(Context, String),

  #[error("{0} did not shutdown gracefully: {1}")]
  ShutdownFailed(Context, String),

  #[error("The supplied id '{0}' does not point to a correct type or valid type: {1}")]
  ReferenceError(String, wick_config::Error),

  #[error("{0}")]
  InitializationFailed(String),

  #[error("Could not find scope '{}' via path {}", .1.as_ref().map_or_else(||Entity::LOCAL,|e|e.component_id()), .0.as_ref().map_or_else(String::new,|v|format!("via path {} ",v.join("::"))))]
  ScopeNotFound(Option<Vec<String>>, Option<Entity>),

  #[error("Invocation error: {0}")]
  InvocationError(String),

  #[error(transparent)]
  ComponentError(#[from] ComponentError),

  #[error("Request timeout out")]
  Timeout,

  #[error("Error starting schedule: {0}")]
  ScheduleStartError(String),

  #[error("Could not render configuration: {0}")]
  Configuration(String),

  #[error("Runtime can not be built without a wick configuration")]
  MissingComponentDefinition,

  #[error("Could not render dotviz: {0}")]
  DotViz(flow_graph_interpreter::error::InterpreterError),
}

impl From<Infallible> for RuntimeError {
  fn from(_: Infallible) -> Self {
    unreachable!()
  }
}