clierrors

package
v0.3.0 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Apr 1, 2026 License: GPL-2.0, GPL-2.0-only Imports: 2 Imported by: 0

Documentation

Overview

Package clierrors provides utilities for formatting error messages in the CLI. It helps create consistent, user-friendly error output with context and suggestions.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func FormatError

func FormatError(operation string, err error) error

FormatError wraps an error with operation context for better CLI output.

Example:

err := fmt.Errorf("connection refused")
formatted := FormatError("connecting to server", err)
// Output: "Error during connecting to server: connection refused"

func FormatMultiError

func FormatMultiError(context string, errs []error) error

FormatMultiError combines multiple errors into a single formatted error.

Example:

errors := []error{
    fmt.Errorf("file not found: rule1.yaml"),
    fmt.Errorf("file not found: rule2.yaml"),
}
err := FormatMultiError("rule validation", errors)
// Output: "Multiple errors during rule validation:
//   - file not found: rule1.yaml
//   - file not found: rule2.yaml"

func FormatScannerError

func FormatScannerError(scannerName string, err error) error

FormatScannerError adds scanner context to an error message.

Example:

err := fmt.Errorf("executable not found in PATH")
formatted := FormatScannerError("semgrep", err)
// Output: "Scanner 'semgrep' error: executable not found in PATH"

func FormatValidationError

func FormatValidationError(flag, message, suggestion string) error

FormatValidationError creates a validation error with a suggestion.

Example:

err := FormatValidationError("--rules", "no rule files specified", "use --rules <file> or --rules-dir <dir>")
// Output: "Validation error for --rules: no rule files specified. Suggestion: use --rules <file> or --rules-dir <dir>"

func WrapWithSuggestion

func WrapWithSuggestion(err error, suggestion string) error

WrapWithSuggestion wraps an error with a helpful suggestion.

Example:

err := fmt.Errorf("semgrep not found in PATH")
wrapped := WrapWithSuggestion(err, "install semgrep: pip install semgrep")
// Output: "semgrep not found in PATH (suggestion: install semgrep: pip install semgrep)"

Types

This section is empty.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL