codex

package
v0.3.3 Latest Latest
Warning

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

Go to latest
Published: Jul 29, 2026 License: MIT Imports: 16 Imported by: 0

Documentation

Overview

Package codex provides a generator for generating error code related implementations.

How to Integrate Generator

ctx := genx.NewContext(&genx.Args{
	Entrypoint: []string{entry},
})
_ = ctx.Execute(context.Background(), genx.Get()...))

Code Definition Conventions

  1. Add `// +genx:code` comment to your error code type.
  2. Define a custom `int` type and use the `@code` annotation in its comment to configure the domain of error (e.g., `// @code domain="OUR_DOMAIN`).
  3. Define constants for your type following the naming conventions below.

Assuming your type is named `ErrorCode`, its prefix will be `ERROR_CODE` (UpperSnakeCase).

  • Undefined Error: Must be named exactly as `<PREFIX>_UNDEFINED`. Example: `ERROR_CODE_UNDEFINED`

  • Specific Errors: Must be named as `<PREFIX>__<ERROR_NAME>` (using a double underscore `__`). Example: `ERROR_CODE__NOT_FOUND`

The error message is extracted from the constant's comment. If no comment is provided, the `<ERROR_NAME>` is used as the fallback message.

Example:

// Code internal error code
// +genx:code
type Code int8

const (
	CODE_UNDEFINED Code = iota
	CODE__ERROR1        // error1 message
	CODE__ERROR2        // error2 message
	CODE__ERROR3
)
Example
cwd := must.NoErrorV(os.Getwd())
entry := filepath.Join(cwd, "..", "testdata", "codex")

ctx := genx.NewContext(&genx.Args{
	Entrypoint: []string{entry},
})
must.NoError(ctx.Execute(context.Background(), genx.Get()...))

Index

Examples

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Error

type Error struct {
	// contains filtered or unexported fields
}

func (*Error) CodeMessageCases

func (e *Error) CodeMessageCases(ctx context.Context) s.Snippet

CodeMessageCases generates code snippet for error message cases

func (*Error) IsValid

func (e *Error) IsValid() bool

type Errors

type Errors struct {
	// contains filtered or unexported fields
}

func NewErrors

func NewErrors(g genx.Context) *Errors

func (*Errors) Resolve

func (es *Errors) Resolve(t types.Type) (*Error, bool)

Jump to

Keyboard shortcuts

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