tangled knot that runs entirely on cloudflare
Something went wrong. Try again.
1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283use 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()), } }}
impl From<knot_artifacts::ArtifactsError> for KnotError { fn from(error: knot_artifacts::ArtifactsError) -> Self { use knot_artifacts::ArtifactsError; match error { ArtifactsError::AlreadyExists(message) => KnotError::Wire(WireError::conflict(message)), ArtifactsError::NotFound(message) => KnotError::Wire(WireError::not_found(message)), ArtifactsError::Upstream(message) => KnotError::upstream(message), ArtifactsError::Binding(message) => KnotError::internal(message), } }}