mirror of
https://github.com/k3s-io/k3s.git
synced 2026-02-03 20:39:49 -05:00
Not currently used, but was useful in tracking down the specific call path for the empty token handling Prints error as: > `msg="Error: starting kubernetes: failed to start cluster: failed to normalize server token; must be in format K10<CA-HASH>::<USERNAME>:<PASSWORD> or <PASSWORD> at github.com/urfave/cli/v2.(*App).RunContext(app.go:333)->github.com/urfave/cli/v2.(*Command).Run(command.go:269)->github.com/urfave/cli/v2.(*Command).Run(command.go:276)->github.com/k3s-io/k3s/pkg/cli/server.Run(server.go:48)->github.com/k3s-io/k3s/pkg/cli/server.run(server.go:629)->github.com/k3s-io/k3s/pkg/server.StartServer(server.go:74)->github.com/k3s-io/k3s/pkg/daemons/control.Server(server.go:72)->github.com/k3s-io/k3s/pkg/cluster.(*Cluster).Start(cluster.go:75)->github.com/k3s-io/k3s/pkg/cluster.Save(storage.go:79)->github.com/k3s-io/k3s/pkg/util.NormalizeToken(token.go:51)"` Signed-off-by: Brad Davidson <brad.davidson@rancher.com>
31 lines
697 B
Go
31 lines
697 B
Go
package util
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"path"
|
|
"runtime"
|
|
"slices"
|
|
"strings"
|
|
)
|
|
|
|
var ErrCommandNoArgs = errors.New("this command does not take any arguments")
|
|
var ErrUnsupportedPlatform = errors.New("unsupported platform")
|
|
|
|
func ErrWithStack(message string) error {
|
|
stack := []string{}
|
|
pcs := make([]uintptr, 32)
|
|
runtime.Callers(2, pcs)
|
|
frames := runtime.CallersFrames(pcs)
|
|
for {
|
|
frame, more := frames.Next()
|
|
if !strings.HasPrefix(frame.Function, "runtime.") {
|
|
stack = append(stack, fmt.Sprintf("%s(%s:%d)", frame.Function, path.Base(frame.File), frame.Line))
|
|
}
|
|
if !more {
|
|
break
|
|
}
|
|
}
|
|
slices.Reverse(stack)
|
|
return errors.New(message + " at " + strings.Join(stack, "->"))
|
|
}
|