Added errors package
All checks were successful
/ test (push) Successful in 13s

This commit is contained in:
Eduard Urbach 2025-06-19 16:56:30 +02:00
parent 1405d2b8b1
commit b7fdd56a8b
Signed by: ed
GPG key ID: 49226B848C78F6C8
6 changed files with 172 additions and 0 deletions

30
src/errors/stack.go Normal file
View file

@ -0,0 +1,30 @@
package errors
import (
"runtime"
"strings"
)
// stack generates a stack trace.
func stack() string {
var (
final []string
buffer = make([]byte, 4096)
n = runtime.Stack(buffer, false)
stack = string(buffer[:n])
lines = strings.Split(stack, "\n")
)
for i := 6; i < len(lines); i += 2 {
line := strings.TrimSpace(lines[i])
space := strings.LastIndex(line, " ")
if space != -1 {
line = line[:space]
}
final = append(final, line)
}
return strings.Join(final, "\n")
}