forked from colinmarc/hdfs
-
Notifications
You must be signed in to change notification settings - Fork 0
/
error.go
44 lines (39 loc) · 1.13 KB
/
error.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
package hdfs
import (
"os"
"syscall"
)
const (
fileNotFoundException = "java.io.FileNotFoundException"
permissionDeniedException = "org.apache.hadoop.security.AccessControlException"
pathIsNotEmptyDirException = "org.apache.hadoop.fs.PathIsNotEmptyDirectoryException"
)
// Error represents a remote java exception from an HDFS namenode or datanode.
type Error interface {
// Method returns the RPC method that encountered an error.
Method() string
// Desc returns the long form of the error code (for example ERROR_CHECKSUM).
Desc() string
// Exception returns the java exception class name (for example
// java.io.FileNotFoundException).
Exception() string
// Message returns the full error message, complete with java exception
// traceback.
Message() string
}
func interpretException(err error) error {
var exception string
if remoteErr, ok := err.(Error); ok {
exception = remoteErr.Exception()
}
switch exception {
case fileNotFoundException:
return os.ErrNotExist
case permissionDeniedException:
return os.ErrPermission
case pathIsNotEmptyDirException:
return syscall.ENOTEMPTY
default:
return err
}
}