command
Version:
v0.0.171
Opens a new window with list of versions in this module.
Published: Oct 3, 2025
License: Apache-2.0
Opens a new window with license information.
Imports: 7
Opens a new window with list of imports.
Imported by: 0
Opens a new window with list of known importers.
README
¶
Error Code System
This directory contains tools for managing error codes in the CLI application.
Error Code Generator
The generate_error_codes.go script generates Go code for error types based on definitions in the error_codes.yaml file at the root of the project.
How it works
-
Error codes are defined in error_codes.yaml in the following format:
errors:
- code: CLI-0001
message: Failed to delete agents
- code: CLI-0002
message: Failed to create project
-
The code can be generated in two ways:
- Using
go generate ./... or make go-generate (recommended)
- Using the legacy method:
go run tools/generate_error_codes.go or make generate
Both methods will:
- Read the YAML file
- Generate appropriate variable names based on the error messages
- Create the
internal/errsystem/errorcodes.go file with the defined error types
Adding new error codes
To add a new error code:
- Edit
error_codes.yaml and add a new entry with a unique code and descriptive message
- Run
go generate ./... or make go-generate to update the Go code
- Use the generated error type in your code
Naming convention
The generator creates variable names by:
- Removing common words like "failed", "unable", "to", etc.
- Converting the remaining words to CamelCase
- Prefixing with "Err"
For example:
- "Failed to delete agents" becomes
ErrDeleteAgents
- "Unable to authenticate user" becomes
ErrAuthenticateUser
Usage in code
Use the generated error types with the errsystem.New function:
import "your-project/internal/errsystem"
func someFunction() error {
// ...
if err != nil {
return errsystem.New(errsystem.ErrDeleteAgents, err)
}
// ...
}
Documentation
¶
There is no documentation for this package.
Source Files
¶
Click to show internal directories.
Click to hide internal directories.