Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
17 changes: 17 additions & 0 deletions pkg/errmetrics/err_msg_windows.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package errmetrics

import (
"syscall"

"golang.org/x/sys/windows"
)

func GetErrorMessage(err uint16) (message string) {
const flags uint32 = syscall.FORMAT_MESSAGE_FROM_SYSTEM
buf := make([]uint16, 300)
_, error := windows.FormatMessage(flags, 0, uint32(err), 0, buf, nil)
if error != nil {
return "unknown error code "
}
return windows.UTF16ToString(buf[:])
}
18 changes: 18 additions & 0 deletions pkg/errmetrics/err_msg_windows_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,18 @@
package errmetrics

import (
"strings"
"syscall"
"testing"

"github.com/stretchr/testify/assert"
)

func TestErrMessage(t *testing.T) {
s1 := GetErrorMessage(uint16(syscall.ERROR_ACCESS_DENIED))
assert.Equal(t, strings.HasPrefix(s1, "Access is denied."), true)

s2 := GetErrorMessage(uint16(syscall.ERROR_INSUFFICIENT_BUFFER))
assert.Equal(t, strings.HasPrefix(s2, "The data area passed to a system call is too small."), true)

}
Loading