-
Notifications
You must be signed in to change notification settings - Fork 253
/
hcserror.go
52 lines (45 loc) · 907 Bytes
/
hcserror.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
45
46
47
48
49
50
51
52
//go:build windows
package hcserror
import (
"errors"
"fmt"
"golang.org/x/sys/windows"
)
type HcsError struct {
title string
rest string
Err error
}
func (e *HcsError) Error() string {
s := e.title
if len(s) > 0 && s[len(s)-1] != ' ' {
s += " "
}
s += fmt.Sprintf("failed in Win32: %s (0x%x)", e.Err, Win32FromError(e.Err))
if e.rest != "" {
if e.rest[0] != ' ' {
s += " "
}
s += e.rest
}
return s
}
func New(err error, title, rest string) error {
// Pass through DLL errors directly since they do not originate from HCS.
var e *windows.DLLError
if errors.As(err, &e) {
return err
}
return &HcsError{title, rest, err}
}
func Win32FromError(err error) uint32 {
var herr *HcsError
if errors.As(err, &herr) {
return Win32FromError(herr.Err)
}
var code windows.Errno
if errors.As(err, &code) {
return uint32(code)
}
return uint32(windows.ERROR_GEN_FAILURE)
}