File tree Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Expand file tree Collapse file tree 3 files changed +51
-2
lines changed Original file line number Diff line number Diff line change 1
1
package errdefs
2
2
3
- import "errors"
3
+ import (
4
+ "errors"
5
+ "syscall"
6
+ )
4
7
5
8
type internalErr struct {
6
9
error
@@ -27,5 +30,20 @@ func Internal(err error) error {
27
30
28
31
func IsInternal (err error ) bool {
29
32
var s system
30
- return errors .As (err , & s )
33
+ if errors .As (err , & s ) {
34
+ return true
35
+ }
36
+
37
+ var errno syscall.Errno
38
+ if errors .As (err , & errno ) {
39
+ if isInternalSyscall (errno ) {
40
+ return true
41
+ }
42
+ }
43
+ return false
44
+ }
45
+
46
+ func isInternalSyscall (err syscall.Errno ) bool {
47
+ _ , ok := syscallErrors ()[err ]
48
+ return ok
31
49
}
Original file line number Diff line number Diff line change
1
+ //go:build linux
2
+ // +build linux
3
+
4
+ package errdefs
5
+
6
+ import (
7
+ "syscall"
8
+
9
+ "golang.org/x/sys/unix"
10
+ )
11
+
12
+ func syscallErrors () map [syscall.Errno ]struct {} {
13
+ return map [syscall.Errno ]struct {}{
14
+ unix .EIO : {}, // I/O error
15
+ unix .ENOMEM : {}, // Out of memory
16
+ unix .EFAULT : {}, // Bad address
17
+ unix .ENOSPC : {}, // No space left on device
18
+ unix .ENOTRECOVERABLE : {}, // State not recoverable
19
+ unix .EHWPOISON : {}, // Memory page has hardware error
20
+ }
21
+ }
Original file line number Diff line number Diff line change
1
+ //go:build !linux
2
+ // +build !linux
3
+
4
+ package errdefs
5
+
6
+ import "syscall"
7
+
8
+ func syscallErrors () map [syscall.Errno ]struct {} {
9
+ return nil
10
+ }
You can’t perform that action at this time.
0 commit comments