Skip to main content

CliError

Enum CliError 

Source
#[non_exhaustive]
pub enum CliError {
Show 16 variants Usage(String), Url(ParseUrlError), MissingKeyFile, KeyFile { path: PathBuf, source: KeyFileError, }, TokenFile { path: PathBuf, source: TokenFileError, }, File { path: PathBuf, source: PrivateFileError, }, FileContents { path: PathBuf, message: String, }, Unreachable { url: String, message: String, }, Protocol(String), Server { status: u16, code: String, message: String, details: Vec<String>, }, Refused(String), InvalidPreview { details: Vec<String>, }, NotConfirmed, TimedOut(String), ExportIncomplete(String), Local(String),
}
Expand description

Why a stratum command failed.

Each variant maps to a stable process exit code through exit_code and to a short machine-readable code through code. A server error displays as code: message, exactly as the node sent it (with control characters escaped). No variant ever carries the operator’s secret key or the bootstrap token.

Variants (Non-exhaustive)§

This enum is marked as non-exhaustive
Non-exhaustive enums could have additional variants added in future. Therefore, when matching against variants of non-exhaustive enums, an extra wildcard arm must be added to account for any future variants.
§

Usage(String)

The command line asks for something impossible, such as an unknown configuration path or a value of the wrong type.

§

Url(ParseUrlError)

The --url value was refused.

§

MissingKeyFile

A command needs the operator key and no --key-file was given.

§

KeyFile

The operator key file could not be created or loaded.

Fields

§path: PathBuf

The key file.

§source: KeyFileError

What went wrong.

§

TokenFile

The bootstrap token file could not be read.

Fields

§path: PathBuf

The token file.

§source: TokenFileError

What went wrong.

§

File

A file other than the key or token file (resume file, claim body file) could not be created, read or removed.

Fields

§path: PathBuf

The file.

§source: PrivateFileError

What went wrong.

§

FileContents

A file was readable but its contents are not what the command needs.

Fields

§path: PathBuf

The file.

§message: String

What is wrong with it.

§

Unreachable

The node could not be reached.

Fields

§url: String

The URL that was tried.

§message: String

The transport error.

§

Protocol(String)

The node answered with something the API contract does not allow.

§

Server

The node refused the request with an error from the API contract.

Fields

§status: u16

The HTTP status.

§code: String

The error.code member.

§message: String

The error.message member.

§details: Vec<String>

Validation errors sent with an invalid error, as path: message.

§

Refused(String)

A local check refused what the node sent: a claim body naming another claimant or node, an expired claim, a manifest with a bad signature or another author, an admission notice for another node or with another hash, a probe that did not read back, an answer naming another member or state than the one acted on, or an existing profile card that does not name its owner.

§

InvalidPreview

A preview reported validation errors, so nothing was sent to apply.

Fields

§details: Vec<String>

The validation errors, as path: message.

§

NotConfirmed

Changes were previewed but not confirmed, so nothing was applied. Also returned by every other command that asks first (join, pod rm, member repair, member cancel): nothing was sent.

§

TimedOut(String)

A bounded wait ran out: join waited for the node to provision the pod (rerunning join continues from where it stopped), or member suspend --wait waited for the suspension to be enforced.

§

ExportIncomplete(String)

export wrote its archive and manifest, but entries changed, vanished or were skipped during the walk; the manifest lists them.

§

Local(String)

Writing output, reading the clock or the random source, or signing failed.

Implementations§

Source§

impl CliError

Source

pub fn exit_code(&self) -> u8

Returns the process exit code; see exit.

§Examples
use stratum_node_cli::{exit, CliError};

let err = CliError::Server {
    status: 409,
    code: "conflict".into(),
    message: "stale base revision".into(),
    details: Vec::new(),
};
assert_eq!(err.to_string(), "conflict: stale base revision");
assert_eq!(err.exit_code(), exit::CONFLICT);
Source

pub fn code(&self) -> &str

Returns a short machine-readable code: the server’s error.code, or one of usage, local, unreachable, protocol, refused, invalid, not_confirmed, timed_out and export_incomplete for failures found by the client.

Source

pub fn hint(&self) -> Option<&'static str>

Returns advice for a server error whose code alone does not say what to do next, or None. The code, message and exit code are not changed; the hint is printed after them.

§Examples
use stratum_node_cli::CliError;

let err = CliError::Server {
    status: 409,
    code: "archive_required".into(),
    message: "no archive for this suspension".into(),
    details: Vec::new(),
};
assert!(err.hint().is_some_and(|hint| hint.contains("--no-archive")));
assert_eq!(CliError::NotConfirmed.hint(), None);
Source

pub fn details(&self) -> &[String]

Returns the validation errors attached to an invalid failure, as path: message lines; empty for every other failure.

Trait Implementations§

Source§

impl Debug for CliError

Source§

fn fmt(&self, f: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Display for CliError

Source§

fn fmt(&self, __formatter: &mut Formatter<'_>) -> Result

Formats the value using the given formatter. Read more
Source§

impl Error for CliError

Source§

fn source(&self) -> Option<&(dyn Error + 'static)>

Returns the lower-level source of this error, if any. Read more
1.0.0 · Source§

fn description(&self) -> &str

👎Deprecated since 1.42.0:

use the Display impl or to_string()

1.0.0 · Source§

fn cause(&self) -> Option<&dyn Error>

👎Deprecated since 1.33.0:

replaced by Error::source, which can support downcasting

Replaced by Error::source.
Source§

fn provide<'a>(&'a self, request: &mut Request<'a>)

🔬This is a nightly-only experimental API. (error_generic_member_access)
Provides type-based access to context intended for error reports. Read more

Auto Trait Implementations§

§

impl !RefUnwindSafe for CliError

§

impl !UnwindSafe for CliError

§

impl Forget for CliError

§

impl Freeze for CliError
where *const u8 is !null: Freeze, PhantomData<u8>: Freeze, *const () is !null: Freeze, PhantomData<ErrorData<CustomOwner>>: Freeze, PhantomData<String>: Freeze,

§

impl Move for CliError

§

impl Send for CliError
where RawVecInner: Send, Repr: Send,

§

impl Sync for CliError
where RawVecInner: Sync, Repr: Sync,

§

impl Unpin for CliError
where *const u8 is !null: Unpin, *const () is !null: Unpin, &'static SimpleMessage: Unpin, *const Custom is !null: Unpin,

§

impl UnsafeUnpin for CliError

Blanket Implementations§

Source§

impl<T> Any for T
where T: 'static + ?Sized,

Source§

fn type_id(&self) -> TypeId

Gets the TypeId of self. Read more
Source§

impl<T> Borrow<T> for T
where T: ?Sized,

Source§

fn borrow(&self) -> &T

Immutably borrows from an owned value. Read more
Source§

impl<T> BorrowMut<T> for T
where T: ?Sized,

Source§

fn borrow_mut(&mut self) -> &mut T

Mutably borrows from an owned value. Read more
Source§

impl<T> From<T> for T

Source§

fn from(t: T) -> T

Returns the argument unchanged.

Source§

impl<T, U> Into<U> for T
where U: From<T>,

Source§

fn into(self) -> U

Calls U::from(self).

That is, this conversion is whatever the implementation of From<T> for U chooses to do.

Source§

impl<T> Same for T

Source§

type Output = T

Should always be Self
Source§

impl<T> ToString for T
where T: Display + ?Sized,

Source§

fn to_string(&self) -> String

Converts the given value to a String. Read more
Source§

impl<T, U> TryFrom<U> for T
where U: Into<T>,

Source§

type Error = !

The type returned in the event of a conversion error.
Source§

fn try_from(value: U) -> Result<T, !>

Performs the conversion.
Source§

impl<T, U> TryInto<U> for T
where U: TryFrom<T>,

Source§

type Error = <U as TryFrom<T>>::Error

The type returned in the event of a conversion error.
Source§

fn try_into(self) -> Result<U, <U as TryFrom<T>>::Error>

Performs the conversion.