1//! The reasons that the core refuses a job.2//!3//! This vocabulary describes a decision of the core. It is not the client's4//! HTTP table and it is not the wire's `ErrorCode`: the web turns a core code5//! into the client code of one API, and the plugin's wire code is translated6//! here on the way in. Keeping the two apart is what lets the core stay a7//! library with no HTTP and no JSON.89use std::fmt;1011/// The reason that the core refused a request or ended a job.12 #[derive(Clone, Copy, PartialEq, Eq, PartialOrd, Ord, Debug)]13pubenumRefusalCode {14/// The name is not in the catalog.15UnknownModel,16/// The model does not declare the capability.17UnknownCapability,18/// The model declares the capability. The host does not serve it.19CapabilityMissing,20/// The kind is not permitted. The mime or the role is incorrect.21InvalidPart,22/// An inline part is more than the body limit.23PayloadTooLarge,24/// The queue is full.25QueueFull,26/// The ledger cannot reserve the bytes.27NoRoom,28/// The plugin failed to start or to load.29LoadFailed,30/// The plugin stopped during the job.31PluginCrashed,32/// The manifest does not agree with the hardware probe.33Mismatch,34/// The plugin did not obey the protocol.35Protocol,36/// The job exceeded its deadline.37Timeout,38/// Two plugins serve one name.39AmbiguousModel,40 }4142implRefusalCode {43/// The word that the core writes and the web copies.44pubfnas_str(self) -> &'static str {45matchself {46RefusalCode::UnknownModel => "unknown_model",47RefusalCode::UnknownCapability => "unknown_capability",48RefusalCode::CapabilityMissing => "capability_missing",49RefusalCode::InvalidPart => "invalid_part",50RefusalCode::PayloadTooLarge => "payload_too_large",51RefusalCode::QueueFull => "queue_full",52RefusalCode::NoRoom => "no_room",53RefusalCode::LoadFailed => "load_failed",54RefusalCode::PluginCrashed => "plugin_crashed",55RefusalCode::Mismatch => "mismatch",56RefusalCode::Protocol => "protocol",57RefusalCode::Timeout => "timeout",58RefusalCode::AmbiguousModel => "ambiguous_model",59 }60 }6162/// The core code for a wire failure.63///64/// A socket fault is not the client's fault, so it maps to `protocol` and65/// keeps its detail. The wire codes that do have a client meaning keep it.66pubfnfrom_wire(code: inf3r_proto::body::ErrorCode) -> RefusalCode {67use inf3r_proto::body::ErrorCodeasWire;68match code {69Wire::UnknownModel => RefusalCode::UnknownModel,70Wire::Capability => RefusalCode::UnknownCapability,71Wire::Part => RefusalCode::InvalidPart,72Wire::Size => RefusalCode::PayloadTooLarge,73Wire::Busy => RefusalCode::QueueFull,74Wire::Timeout => RefusalCode::Timeout,75Wire::Dependency => RefusalCode::LoadFailed,76Wire::Version | Wire::Frame | Wire::Stream | Wire::Credit | Wire::Internal => {77RefusalCode::Protocol78 }79Wire::Cancelled => RefusalCode::Timeout,80 }81 }82 }8384impl fmt::DisplayforRefusalCode {85fnfmt(&self, f: &mut fmt::Formatter<'_>) -> fmt::Result {86 f.write_str(self.as_str())87 }88 }8990/// A refusal with the request that caused it.91 #[derive(Clone, PartialEq, Eq, Debug)]92pubstructRefusal {93/// The core code.94pub code: RefusalCode,95/// One sentence for a human.96pub message: String,97/// The identifier that the client sent.98pub request_id: String,99 }100101implRefusal {102/// A refusal with the code's word as its first message.103pubfnnew(code: RefusalCode, request_id: implInto<String>) -> Refusal {104Refusal {105 code,106 message: code.as_str().to_string(),107 request_id: request_id.into(),108 }109 }110111/// The same refusal with a message.112pubfnwith(self, message: implInto<String>) -> Refusal {113Refusal {114 message: message.into(),115 ..self116 }117 }118 }