OpenDAL Error Mapping in the dav-server Integration#
The dav-server integration bridges OpenDAL's rich error model to the limited three-value error type that the dav_server crate exposes to WebDAV clients. The entire mapping lives in a single function, convert_error, in integrations/dav-server/src/utils.rs.
The Mapping Function#
convert_error takes an opendal::Error and returns a dav_server::fs::FsError:
OpenDAL ErrorKind | WebDAV FsError |
|---|---|
AlreadyExists | Exists |
IsSameFile | Exists |
NotFound | NotFound |
| (everything else) | GeneralFailure |
The catch-all _ arm collapses all other OpenDAL error kinds — including PermissionDenied, Unauthorized, InvalidArgument, RateLimited, and others — into GeneralFailure . This is a deliberate trade-off: the WebDAV protocol surface provides no finer-grained distinctions for most of these conditions, so surfacing them as GeneralFailure is the safest option for client compatibility.
Where convert_error Is Called#
convert_error is imported and used consistently across all three operational layers of the integration:
fs.rs— Filesystem operations: All top-level WebDAV methods (read_dir,metadata,create_dir,remove_file,rename,copy) callconvert_errorwhen mapping OpenDAL results toFsError. For example,metadatauses it at line 114,read_dirat line 100, andrename/copyat lines 188, 203.file.rs— File open/stat operations:OpendalFile::opencallsconvert_errorwhen acquiring a reader or writer from OpenDAL. TheDavFile::metadatamethod also routes through it .dir.rs: Directory stream construction callsconvert_errorwhen the underlying lister fails .
Important Nuances#
fs_pathconversion errors bypassconvert_errorand directly returnFsError::GeneralFailure— a non-OpenDAL error path .create_dircontains additional pre-flight checks: Parent-existence and duplicate-directory checks issue explicitFsError::NotFoundandFsError::Existsvalues before any OpenDAL call, not viaconvert_error. This enforces RFC 2518 §8.3.1 semantics directly in the integration layer.- I/O errors inside file reads/writes/seeks are also mapped directly to
FsError::GeneralFailurewithout going throughconvert_error, because they originate from theAsyncRead/AsyncWritetrait layer, not from OpenDALErrorvalues .
Extending the Mapping#
If a new OpenDAL ErrorKind needs a distinct WebDAV response (e.g., mapping PermissionDenied to a future FsError::Forbidden), add a new arm to the match in utils.rs. All call sites automatically benefit without changes elsewhere.