Skip to main content

ErrorKind

Enum ErrorKind 

Source
#[non_exhaustive]
pub enum ErrorKind {
Show 20 variants AuthRequired, SigningRequired, AccessDenied, NotFound, AlreadyExists, SharingViolation, IsADirectory, NotADirectory, DiskFull, ConnectionLost, TimedOut, Cancelled, SessionExpired, DfsReferral, InvalidData, TooLarge, Io, InvalidName, Unsupported, Other,
}
Expand description

High-level error classification.

Maps protocol-level NTSTATUS codes and other errors into categories that consumers can match on without understanding SMB internals.

use smb2::ErrorKind;

match client.read_file(share, "photo.jpg").await {
    Ok(data) => println!("read {} bytes", data.len()),
    Err(e) => match e.kind() {
        ErrorKind::NotFound => println!("file doesn't exist"),
        ErrorKind::AlreadyExists => println!("name is already taken"),
        ErrorKind::AccessDenied => println!("no permission"),
        ErrorKind::SigningRequired => println!("server requires signing, use credentials"),
        ErrorKind::AuthRequired => println!("server requires authentication"),
        ErrorKind::SharingViolation => println!("file is in use by another client"),
        ErrorKind::IsADirectory => println!("path is a directory, not a file"),
        ErrorKind::NotADirectory => println!("path is a file, not a directory"),
        ErrorKind::DiskFull => println!("volume is full"),
        ErrorKind::ConnectionLost => { client.reconnect().await?; }
        _ => return Err(e),
    }
}

§Stability

ErrorKind is #[non_exhaustive]: future versions may add variants for status codes that currently fall through to ErrorKind::Other. Match statements should always include a _ arm. Adding a variant is treated as a non-breaking change.

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.
§

AuthRequired

The server requires authentication (guest/anonymous not allowed).

§

SigningRequired

The server requires message signing (guest sessions are unsigned).

§

AccessDenied

Permission denied (valid credentials, but no access to this resource).

§

NotFound

The file, directory, or share was not found.

§

AlreadyExists

A file or directory with the given name already exists.

Returned by Create (and operations that wrap it, like create_directory) when the target name is taken. Useful for callers that want to merge into an existing directory or surface a friendly “name already taken” message.

§

SharingViolation

The file is in use by another client.

§

IsADirectory

The target path is a directory, but the operation expected a file.

Typically seen when calling delete_file against a directory entry — the caller can fall back to delete_directory after detecting this.

§

NotADirectory

The target path is a file, but the operation expected a directory.

Typically seen when calling list_directory against a file entry.

§

DiskFull

The volume is full (write failed).

§

ConnectionLost

The network connection was lost.

§

TimedOut

The operation timed out.

§

Cancelled

The operation was cancelled by the caller.

§

SessionExpired

The session expired (call reconnect()).

§

DfsReferral

The path requires DFS referral resolution.

§

InvalidData

Invalid data or malformed response.

§

TooLarge

The file is too large for a single-read path.

Returned by Tree::read_file / read_file_compound / read_file_compound_sized when the file is bigger than the READ they issued for it. Switch to read_file_pipelined, which reads any size in chunked, pipelined READs.

§

Io

An I/O error (transport or callback). Not necessarily a connection loss.

Distinct from ConnectionLost: the connection may still be usable. For example, a callback error in write_file_streamed produces Io, but the connection is still in a clean state.

§

InvalidName

The name is not usable on this server, whatever it is asked to do.

Distinct from NotFound: the file may or may not exist, and the server never got far enough to find out, so retrying the same name can only fail again. A consumer’s useful response is to change the name, or tell the person that this one will not work here.

The characters SMB2 forbids outright – ", *, :, <, >, ?, \, |, the control characters, and a trailing space or period – are mapped out of the way automatically (see crate::name), so this is what is left over: a reserved Windows device name (CON, NUL, LPT1), a name past the server’s own length limit, or a character its filesystem cannot store. Maps from STATUS_OBJECT_NAME_INVALID.

§

Unsupported

The server does not support the requested operation.

Returned when the server rejects an operation it does not implement – for example, an older Samba build or NAS firmware that lacks server-side copy. Consumers branch on this to fall back to a client-side path (for server-side copy, a plain read-then-write). Maps from STATUS_NOT_SUPPORTED, STATUS_INVALID_DEVICE_REQUEST, and STATUS_NOT_IMPLEMENTED.

§

Other

A protocol error not covered by other variants.

Use Error::status() to get the raw NTSTATUS code. Some defined NtStatus codes deliberately fall through here today (DELETE_PENDING, INSUFFICIENT_RESOURCES, INSUFF_SERVER_RESOURCES, and similar) — they don’t yet have a dedicated ErrorKind because no consumer needs to branch on them. Promoting one to its own variant is non-breaking, which is how OBJECT_NAME_INVALID became InvalidName.

Trait Implementations§

Source§

impl Clone for ErrorKind

Source§

fn clone(&self) -> ErrorKind

Returns a duplicate of the value. Read more
1.0.0 (const: unstable) · Source§

fn clone_from(&mut self, source: &Self)

Performs copy-assignment from source. Read more
Source§

impl Copy for ErrorKind

Source§

impl Debug for ErrorKind

Source§

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

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

impl Eq for ErrorKind

Source§

impl PartialEq for ErrorKind

Source§

fn eq(&self, other: &ErrorKind) -> bool

Equality operator ==. Read more
1.0.0 (const: unstable) · Source§

fn ne(&self, other: &Rhs) -> bool

Inequality operator !=. Read more
Source§

impl StructuralPartialEq for ErrorKind

Auto Trait Implementations§

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> CloneToUninit for T
where T: Clone,

Source§

unsafe fn clone_to_uninit(&self, dest: *mut u8)

🔬This is a nightly-only experimental API. (clone_to_uninit)
Performs copy-assignment from self to dest. 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> ToOwned for T
where T: Clone,

Source§

type Owned = T

The resulting type after obtaining ownership.
Source§

fn to_owned(&self) -> T

Creates owned data from borrowed data, usually by cloning. Read more
Source§

fn clone_into(&self, target: &mut T)

Uses borrowed data to replace owned data, usually by cloning. 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.