Documentation
¶
Index ¶
- Variables
- func CleanAPIError(err error) string
- func CleanErr(err error) error
- func ClientFlags(short bool) []cli.Flag
- func Describe(err error) string
- func ExplicitServerAddr(cmd *cli.Command) *config.ServerAddr
- func FormatError(err error) string
- func GetClient(cmd *cli.Command) (*apiclient.ApiClient, error)
- func GetServerAddr(cmd *cli.Command) *config.ServerAddr
- func WebSocketError(what string, resp *http.Response, err error) error
Constants ¶
This section is empty.
Variables ¶
var ErrNoServer = errors.New("no server configured")
ErrNoServer is returned when a command needs a server but none was given on the command line, in the environment or in a saved connection.
Functions ¶
func CleanAPIError ¶ added in v0.36.0
CleanAPIError strips the transport framing the REST client wraps around non-2xx responses ("unexpected status code: 400: …") and returns just the server's error message.
func CleanErr ¶ added in v0.37.0
CleanErr wraps err so its text is CleanAPIError's (the server's message without the REST client's framing) while errors.As still finds the underlying HTTPError, letting FormatError add the status and a hint.
func ClientFlags ¶ added in v0.37.0
ClientFlags returns the flags that choose the server a command talks to: an explicit --server and --token, else the alias (default "default") from the config file's client.connection section. Commands that already use -s, -t or -a for something else take them without short names.
func Describe ¶ added in v0.37.0
Describe is FormatError without the "Error: " prefix, for warnings and per-item failures printed while a command carries on.
func ExplicitServerAddr ¶ added in v0.34.0
func ExplicitServerAddr(cmd *cli.Command) *config.ServerAddr
ExplicitServerAddr returns the server the user explicitly targeted via a --server and --token pair (flag or env), or via an --alias that resolves in the config file. It returns nil when neither is given, so inside a space callers can fall back to the server that owns the space.
Note the both-non-empty rule for the flags: spaces always have KNOT_SERVER set to the owning server's URL, so a token alone must never count as an explicit target. An --alias is only honoured when actually given on the command line — the "default" alias is never consulted implicitly, so a config file carried into a space cannot silently redirect tunnels.
func FormatError ¶ added in v0.37.0
FormatError turns an error from a command into the single line shown on the terminal: "Error: <what failed>: <why>. <what to do next>". It recognises the API client's HTTPError (status code and server message) and the usual network failures (connection refused, unknown host, certificate problems, timeouts) anywhere in the error chain and rewrites them in plain words, keeping whatever context the command wrapped around them.
func GetServerAddr ¶ added in v0.25.0
func GetServerAddr(cmd *cli.Command) *config.ServerAddr
func WebSocketError ¶ added in v0.37.0
WebSocketError describes a failed websocket dial. When the server answered the handshake with an error status it becomes an HTTPError, so the status is reported (and hinted) like any other API failure.
Types ¶
This section is empty.