diff --git a/cmd/headscale/cli/debug.go b/cmd/headscale/cli/debug.go index 226ae5e7..8010a9be 100644 --- a/cmd/headscale/cli/debug.go +++ b/cmd/headscale/cli/debug.go @@ -9,6 +9,16 @@ import ( "google.golang.org/grpc/status" ) +const ( + keyLength = 64 + errPreAuthKeyTooShort = Error("key too short, must be 64 hexadecimal characters") +) + +// Error is used to compare errors as per https://dave.cheney.net/2016/04/07/constant-errors +type Error string + +func (e Error) Error() string { return string(e) } + func init() { rootCmd.AddCommand(debugCmd) @@ -77,8 +87,8 @@ var createNodeCmd = &cobra.Command{ return } - if len(machineKey) != 64 { - err = fmt.Errorf("key '%s' too short, must be 64 hexadecimal characters", machineKey) + if len(machineKey) != keyLength { + err = errPreAuthKeyTooShort ErrorOutput( err, fmt.Sprintf("Error: %s", err),