opendal/services/hdfs_native/
error.rs1use hdfs_native::HdfsError;
19
20use crate::*;
21
22pub fn parse_hdfs_error(hdfs_error: HdfsError) -> Error {
24 let (kind, retryable, msg) = match &hdfs_error {
25 HdfsError::IOError(err) => (ErrorKind::Unexpected, false, err.to_string()),
26 HdfsError::DataTransferError(msg) => (ErrorKind::Unexpected, false, msg.clone()),
27 HdfsError::ChecksumError => (
28 ErrorKind::Unexpected,
29 false,
30 "checksums didn't match".to_string(),
31 ),
32 HdfsError::UrlParseError(err) => (ErrorKind::Unexpected, false, err.to_string()),
33 HdfsError::AlreadyExists(msg) => (ErrorKind::AlreadyExists, false, msg.clone()),
34 HdfsError::OperationFailed(msg) => (ErrorKind::Unexpected, false, msg.clone()),
35 HdfsError::RPCError(msg0, msg1) => {
36 if msg0.contains("java.io.FileNotFoundException") {
37 (ErrorKind::NotFound, false, msg1.clone())
38 } else {
39 (ErrorKind::Unexpected, false, msg1.clone())
40 }
41 }
42 HdfsError::FileNotFound(msg) => (ErrorKind::NotFound, false, msg.clone()),
43 HdfsError::BlocksNotFound(msg) => (ErrorKind::NotFound, false, msg.clone()),
44 HdfsError::IsADirectoryError(msg) => (ErrorKind::IsADirectory, false, msg.clone()),
45 _ => (
46 ErrorKind::Unexpected,
47 false,
48 "unexpected error from hdfs".to_string(),
49 ),
50 };
51
52 let mut err = Error::new(kind, msg).set_source(hdfs_error);
53
54 if retryable {
55 err = err.set_temporary();
56 }
57
58 err
59}