Something went wrong. Try again.
Monorepo for Tangled tangled.org
Something went wrong. Try again.
Rust
12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667use knot_gitcore::CoreError;use knot_wire::WireError;
#[derive(Debug, Clone)]pub enum KnotError { Wire(WireError), Git(CoreError),}
impl KnotError { pub fn internal(message: impl Into<String>) -> Self { KnotError::Wire(WireError::internal(message)) }
pub fn upstream(message: impl Into<String>) -> Self { KnotError::Wire(WireError::upstream_unavailable(message)) }
pub fn into_wire(self) -> WireError { match self { KnotError::Wire(error) => error, KnotError::Git(error) => error.into(), } }}
impl std::fmt::Display for KnotError { fn fmt(&self, f: &mut std::fmt::Formatter<'_>) -> std::fmt::Result { match self { KnotError::Wire(error) => error.fmt(f), KnotError::Git(error) => error.fmt(f), } }}
impl From<WireError> for KnotError { fn from(error: WireError) -> Self { KnotError::Wire(error) }}
impl From<CoreError> for KnotError { fn from(error: CoreError) -> Self { KnotError::Git(error) }}
impl From<worker::Error> for KnotError { fn from(error: worker::Error) -> Self { KnotError::internal(error.to_string()) }}
impl From<knot_atproto::AtprotoError> for KnotError { fn from(error: knot_atproto::AtprotoError) -> Self { use knot_atproto::AtprotoError; if error.is_transient() { return KnotError::Wire(WireError::upstream_unavailable(error.to_string())); } match error { AtprotoError::Resolve(_) => KnotError::Wire(WireError::invalid_request(error.to_string())), AtprotoError::PlcSubmit { .. } => KnotError::Wire(WireError::bad_gateway(error.to_string())), other => KnotError::internal(other.to_string()), } }}