internal

package
v0.8.0 Latest Latest
Warning

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

Go to latest
Published: Nov 10, 2025 License: MPL-2.0 Imports: 18 Imported by: 0

Documentation

Overview

discovery.go Config discovery and loading logic for smarterr

merge.go Config merging logic for smarterr

types.go Core HCL struct definitions for smarterr

Index

Constants

View Source
const (
	SeverityError   = "Error"
	SeverityWarning = "Warning"
	SeverityInfo    = "Info"
)
View Source
const (
	// ConfigFileName is the name of the configuration file
	// that contains the configuration for smarterr.
	ConfigFileName = "smarterr.hcl"
)
View Source
const (
	SmarterrContextKey = "smarterrCallID"
)

Variables

This section is empty.

Functions

func CollectTemplateVariables added in v0.2.0

func CollectTemplateVariables(tmpl *template.Template) []string

CollectTemplateVariables walks the template AST and returns a list of all variable names referenced.

func Debugf

func Debugf(format string, args ...any)

Debugf emits a debug message if internal debug output is enabled.

func EnableDebug

func EnableDebug(cfg *Config)

EnableDebug sets up internal debug output based on the Smarterr block in config.

func EnableDebugForce added in v0.2.0

func EnableDebugForce()

EnableDebugForce ...

Types

type Config

type Config struct {
	Smarterr     *Smarterr    `hcl:"smarterr,block"`
	Tokens       []Token      `hcl:"token,block"`
	Hints        []Hint       `hcl:"hint,block"`
	Parameters   []Parameter  `hcl:"parameter,block"`
	StackMatches []StackMatch `hcl:"stack_match,block"`
	Templates    []Template   `hcl:"template,block"`
	Transforms   []Transform  `hcl:"transform,block"`
}

Config represents the top-level configuration for smarterr.

func LoadConfig

func LoadConfig(ctx context.Context, fsys FileSystem, relStackPaths []string, baseDir string) (*Config, error)

LoadConfig loads and merges configuration files from a filesystem.

func (*Config) RenderTemplate

func (cfg *Config) RenderTemplate(ctx context.Context, name string, values map[string]any) (string, error)

RenderTemplate renders a named template from the config using the provided token values.

type ContextKey added in v0.4.0

type ContextKey string

type FileSystem

type FileSystem interface {
	Open(name string) (fs.File, error)
	ReadFile(name string) ([]byte, error)
	WalkDir(root string, fn fs.WalkDirFunc) error
	Exists(name string) bool
}

FileSystem defines an interface for filesystem operations, including file existence checks.

type Hint

type Hint struct {
	Name          string  `hcl:"name,label"`
	ErrorContains *string `hcl:"error_contains,optional"`
	RegexMatch    *string `hcl:"regex_match,optional"`
	Suggestion    string  `hcl:"suggestion"`
}

type Parameter

type Parameter struct {
	Name  string `hcl:"name,label"`
	Value string `hcl:"value,attr"`
}

type Runtime

type Runtime struct {
	Config     *Config
	Args       map[string]any
	Error      error
	Diagnostic diag.Diagnostic // single diagnostic for enrichment context
}

func NewRuntime

func NewRuntime(ctx context.Context, cfg *Config, err error, kv ...any) *Runtime

func NewRuntimeForDiagnostic added in v0.3.0

func NewRuntimeForDiagnostic(ctx context.Context, cfg *Config, diagnostic diag.Diagnostic, kv ...any) *Runtime

func (*Runtime) BuildTokenValueMap

func (rt *Runtime) BuildTokenValueMap(ctx context.Context) map[string]any

BuildTokenValueMap resolves all tokens in the config and returns a map of token name to value.

type Smarterr

type Smarterr struct {
	Debug          bool    `hcl:"debug,optional"`
	TokenErrorMode *string `hcl:"token_error_mode,optional"` // "detailed", "placeholder", "empty" (default: "empty")
	HintJoinChar   *string `hcl:"hint_join_char,optional"`
	HintMatchMode  *string `hcl:"hint_match_mode,optional"` // "all" (default), "first"
}

Smarterr represents settings for how smarterr works such as debugging, token error mode, etc.

type StackMatch

type StackMatch struct {
	Name       string `hcl:"name,label"`
	CalledFrom string `hcl:"called_from,optional"`
	Display    string `hcl:"display"`
}

type Template

type Template struct {
	Name   string `hcl:"name,label"`
	Format string `hcl:"format"`
}

Template represents a named text/template for formatting error messages or diagnostics.

type Token

type Token struct {
	Name            string              `hcl:"name,label"`
	Source          string              `hcl:"source,optional"`
	Parameter       *string             `hcl:"parameter,optional"`
	StackMatches    []string            `hcl:"stack_matches,optional"`
	Arg             *string             `hcl:"arg,optional"`
	Context         *string             `hcl:"context,optional"`
	Transforms      []string            `hcl:"transforms,optional"`
	FieldTransforms map[string][]string `hcl:"field_transforms,optional"`
}

Token represents a token in the configuration, which can be used for error message formatting.

func (*Token) Resolve

func (t *Token) Resolve(ctx context.Context, rt *Runtime) any

Resolve takes a token and resolves it based on the runtime information. It supports various source types such as parameters, context values, error inspection, call stack inspection, and runtime arguments.

type Transform

type Transform struct {
	Name  string          `hcl:"name,label"`
	Steps []TransformStep `hcl:"step,block"`
}

type TransformStep

type TransformStep struct {
	Type    string  `hcl:"type,label"`
	Value   *string `hcl:"value,optional"`
	Regex   *string `hcl:"regex,optional"`
	With    *string `hcl:"with,optional"`
	Recurse *bool   `hcl:"recurse,optional"`
}

type WrappedFS

type WrappedFS struct {
	FS fs.FS
}

WrappedFS implements FileSystem for a generic fs.FS.

func NewWrappedFS

func NewWrappedFS(root string) *WrappedFS

func (*WrappedFS) Exists

func (d *WrappedFS) Exists(path string) bool

Exists checks if a file exists in the wrapped filesystem.

func (*WrappedFS) Open

func (d *WrappedFS) Open(name string) (fs.File, error)

func (*WrappedFS) ReadFile

func (d *WrappedFS) ReadFile(name string) ([]byte, error)

func (*WrappedFS) WalkDir

func (d *WrappedFS) WalkDir(root string, fn fs.WalkDirFunc) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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