#[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
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.