Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

tetragon/windows: Port package errmetrics to Windows #3534

Merged
merged 1 commit into from
Mar 25, 2025
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