#[non_exhaustive]pub enum Error {
Show 26 variants
EngineBusy,
WeightsAlreadyLoaded,
WrongModel {
expected: Model,
},
UnsupportedWeights {
tag: u32,
},
Load,
LoadFailed {
model: Model,
detail: String,
},
Init,
InitFailed {
detail: String,
},
Complete {
detail: String,
},
Truncated {
capacity: usize,
},
Embed,
EmbedFailed {
detail: String,
},
InteriorNul {
field: &'static str,
},
SpeechModelNotLoaded,
AudioTooLong {
samples: usize,
},
NonFiniteSample {
index: usize,
},
Transcribe {
detail: String,
},
EmbedAudio {
detail: String,
},
UnsupportedLanguage {
code: String,
},
InvalidKeyword {
keyword: String,
},
Envelope {
text: String,
source: Error,
},
Arguments {
source: Error,
},
Tools {
source: Error,
},
Io(Error),
Download {
url: String,
detail: String,
},
ChecksumMismatch {
expected: String,
actual: String,
},
}Expand description
Everything that can go wrong while loading weights or driving the engine.
The enum is #[non_exhaustive]: matching it needs a _ arm, and new variants are not a
breaking change.
§Examples
use cactus_rs::Error;
let err = Error::Truncated { capacity: 65_536 };
assert!(err.to_string().contains("65536"));
assert!(err.to_string().contains("Help:"));Variants (Non-exhaustive)§
This enum is marked as non-exhaustive
EngineBusy
Another instance of the same model is alive in this process: a second
Needle while one exists, or a second Whistle while one exists.
WeightsAlreadyLoaded
Weights of the same kind were already loaded, and the new archive is a different one.
WrongModel
The archive holds the other kind of model than the one being built.
Needle 3 and Whistle archives carry the same magic tag, so the kind is read from the archive’s tensor directory before the engine sees it. A wrong archive is never loaded: the engine would have swapped it in over the model of that kind.
UnsupportedWeights
The archive is not a Needle 3 or Whistle .cact file: a wrong magic tag, or the right
one over a tensor directory that cannot be read.
Fields
Load
Not returned since 0.2.1; see Error::LoadFailed, which carries the engine’s reason.
LoadFailed
needle_load rejected the archive; detail is the engine’s own reason.
Fields
Init
Not returned since 0.2.1; see Error::InitFailed, which carries the engine’s reason.
InitFailed
needle_init failed; detail includes the engine’s reason (e.g. the measured token count
when the prefix overflows the context).
Fields
Complete
needle_complete failed, with whatever detail the engine wrote into the buffer.
Fields
Truncated
The engine filled the output buffer and silently cut the envelope short.
Embed
Not returned since 0.2.1; see Error::EmbedFailed, which carries the engine’s reason.
EmbedFailed
needle_embed failed on text: the engine’s reason, or a float-count mismatch (“engine
wrote N floats, expected D”).
InteriorNul
A string bound for the C API contains an interior NUL byte.
Fields
SpeechModelNotLoaded
An audio completion was asked for, and no speech model is loaded.
AudioTooLong
The clip is longer than the engine accepts.
NonFiniteSample
A sample of the clip is NaN or infinite.
Transcribe
needle_transcribe failed, with the engine’s reason.
EmbedAudio
needle_embed failed on a clip, with the engine’s reason.
UnsupportedLanguage
A language code is not one Whistle transcribes.
InvalidKeyword
A keyword holds a line break.
Envelope
The engine’s response was not the JSON envelope this crate expects.
Fields
Arguments
A tool call’s arguments did not fit the requested Rust type.
Tools
The tool declarations could not be written as JSON for the engine.
Io(Error)
Reading or writing a file failed.
Download
Downloading the weight archive failed.
Fields
ChecksumMismatch
A downloaded archive did not match its pinned SHA-256.
Implementations§
Source§impl Error
impl Error
Sourcepub fn detail(&self) -> Option<&str>
pub fn detail(&self) -> Option<&str>
The underlying reason in the error’s own words, for the variants that carry one.
That is the engine’s text for Error::Complete, Error::Transcribe,
Error::EmbedAudio, Error::LoadFailed, Error::InitFailed and
Error::EmbedFailed, and the HTTP client’s for Error::Download. Every other
variant returns None.
§Examples
use cactus_rs::Error;
let err = Error::InitFailed {
detail: "prefix of 40000 tokens exceeds the context".to_owned(),
};
assert_eq!(err.detail(), Some("prefix of 40000 tokens exceeds the context"));
assert_eq!(Error::EngineBusy.detail(), None);Sourcepub fn envelope(text: &str, source: Error) -> Self
pub fn envelope(text: &str, source: Error) -> Self
Builds an Error::Envelope with the response text truncated to a loggable excerpt.
§Examples
use cactus_rs::Error;
let source = serde_json::from_str::<serde_json::Value>("{").unwrap_err();
let err = Error::envelope(&"x".repeat(1000), source);
assert!(err.to_string().contains("(truncated)"));Trait Implementations§
Source§impl Error for Error
impl Error for Error
Source§fn source(&self) -> Option<&(dyn Error + 'static)>
fn source(&self) -> Option<&(dyn Error + 'static)>
1.0.0 · Source§fn description(&self) -> &str
fn description(&self) -> &str
use the Display impl or to_string()