Documentation ¶
Overview ¶
Package clog provides rich error types and logging helpers for coder-cli.
clog encourages returning error types rather than logging them and failing with os.Exit as they happen. Error, Fatal, and Warn allow downstream functions to return errors with rich formatting information while preserving the original, single-line error chain.
Index ¶
- Constants
- func Bold(a string) string
- func Causef(format string, a ...interface{}) string
- func Hintf(format string, a ...interface{}) string
- func Log(err error)
- func LogInfo(header string, lines ...string)
- func LogSuccess(header string, lines ...string)
- func LogWarn(header string, lines ...string)
- func Tipf(format string, a ...interface{}) string
- type CLIError
- type CLIMessage
- type ErrGroup
Constants ¶
const BlankLine = ""
BlankLine is an empty string meant to be used in CLIMessage and CLIError construction.
Variables ¶
This section is empty.
Functions ¶
func Causef ¶
Causef formats according to the given format specifier and prepends a bolded "cause: " header.
func Hintf ¶
Hintf formats according to the given format specifier and prepends a bolded "hint: " header.
func Log ¶
func Log(err error)
Log logs the given error to stderr, defaulting to "fatal" if the error is not a CLIError. If the error is a CLIError, the plain error chain is ignored and the CLIError is logged on its own.
func LogSuccess ¶
LogSuccess prints the given info message to stderr.
Types ¶
type CLIError ¶
type CLIError struct { CLIMessage // contains filtered or unexported fields }
CLIError wraps a CLIMessage and allows consumers to treat it as a normal error.
type CLIMessage ¶
CLIMessage provides a human-readable message for CLI errors and messages.
func (CLIMessage) String ¶
func (m CLIMessage) String() string
String formats the CLI message for consumption by a human.
type ErrGroup ¶
ErrGroup wraps the /x/sync/errgroup.(Group) and adds clog logging and rich error propagation.
Take for example, a case in which we are concurrently stopping a slice of environments. In this case, we want to log errors as they happen, not pass them through the callstack as errors. When the operations complete, we want to log how many, if any, failed. The caller is still expected to handle success and info logging.
func LoggedErrGroup ¶
func LoggedErrGroup() ErrGroup
LoggedErrGroup gives an error group with error logging and error propagation handled automatically.