errorhandler

package
v1.23.14 Latest Latest
Warning

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

Go to latest
Published: Apr 4, 2026 License: MIT Imports: 9 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type EnvironmentResolver

type EnvironmentResolver interface {
	Getenv(key string) string
}

EnvironmentResolver provides access to azd environment values like AZURE_LOCATION and AZURE_SUBSCRIPTION_ID.

type ErrorHandler

type ErrorHandler interface {
	// Handle inspects the error and returns a suggestion if applicable.
	// The rule parameter provides access to the matching YAML rule,
	// allowing the handler to merge in links or other static data.
	// Returns nil if this handler cannot produce a suggestion.
	Handle(ctx context.Context, err error, rule ErrorSuggestionRule) *ErrorWithSuggestion
}

ErrorHandler processes an error and returns a user-friendly suggestion. Handlers are registered by name in the IoC container and referenced from YAML rules via the "handler" field.

func NewResourceNotAvailableHandler

func NewResourceNotAvailableHandler(
	locationResolver ResourceTypeLocationResolver,
	env EnvironmentResolver,
) ErrorHandler

NewResourceNotAvailableHandler creates a new ResourceNotAvailableHandler.

type ErrorHandlerPipeline

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

ErrorHandlerPipeline evaluates error suggestion rules from YAML and optionally invokes named ErrorHandlers for dynamic suggestions.

func NewErrorHandlerPipeline

func NewErrorHandlerPipeline(handlerResolver HandlerResolver) *ErrorHandlerPipeline

NewErrorHandlerPipeline creates a new pipeline with rules loaded from the embedded YAML.

func (*ErrorHandlerPipeline) Process

Process evaluates all rules in order against the given error. Returns the first matching suggestion, or nil if no rules match.

Rule evaluation:

  1. If errorType is set → find matching typed error via reflection
  2. If properties is set → check property values on the matched error
  3. If patterns is set → check text patterns against error message
  4. All specified conditions must pass for a match
  5. If handler is set → invoke named handler for dynamic suggestion
  6. Otherwise → return static suggestion from rule fields

func (*ErrorHandlerPipeline) ProcessWithRules

func (p *ErrorHandlerPipeline) ProcessWithRules(
	ctx context.Context,
	err error,
	rules []ErrorSuggestionRule,
) *ErrorWithSuggestion

ProcessWithRules evaluates the given rules against the error. This is useful for testing with custom rule sets.

type ErrorLink struct {
	// URL is the link target (required)
	URL string
	// Title is the display text (optional — if empty, the URL is shown)
	Title string
}

ErrorLink represents a reference link with a URL and optional title.

type ErrorSuggestionRule

type ErrorSuggestionRule struct {
	// Patterns is a list of strings to match against error messages.
	// By default, strings are matched as case-insensitive substrings.
	// Set Regex to true to treat all patterns and property values
	// as regular expressions.
	Patterns []string `yaml:"patterns,omitempty"`

	// ErrorType is the Go struct type name to match via reflection.
	// The error chain is walked using errors.As semantics.
	// Example: "AzureDeploymentError", "ResponseError"
	ErrorType string `yaml:"errorType,omitempty"`

	// Properties is a map of dot-path property names to expected values.
	// Properties are resolved via reflection on the matched error type.
	// By default, values are matched as case-insensitive substrings.
	// Set Regex to true to treat values as regular expressions.
	Properties map[string]string `yaml:"properties,omitempty"`

	// Regex enables regular expression matching for all patterns
	// and property values in this rule.
	Regex bool `yaml:"regex,omitempty"`

	// Handler is the name of a registered ErrorHandler to invoke.
	// When set, the handler computes the suggestion dynamically
	// instead of using the static message/suggestion/links fields.
	Handler string `yaml:"handler,omitempty"`

	// Message is a user-friendly error message.
	Message string `yaml:"message,omitempty"`

	// Suggestion is the actionable next steps for the user.
	Suggestion string `yaml:"suggestion,omitempty"`

	// Links is a list of reference links (each with a URL and
	// optional title).
	Links []RuleLink `yaml:"links,omitempty"`
}

ErrorSuggestionRule defines a single rule that maps error patterns to an actionable suggestion.

type ErrorSuggestionsConfig

type ErrorSuggestionsConfig struct {
	// Rules is the ordered list of error suggestion rules.
	// Rules are evaluated in order; the first match wins.
	Rules []ErrorSuggestionRule `yaml:"rules"`
}

ErrorSuggestionsConfig is the root structure for error_suggestions.yaml.

type ErrorWithSuggestion

type ErrorWithSuggestion struct {
	// Err is the original underlying error
	Err error
	// Message is a user-friendly explanation of what went wrong
	Message string
	// Suggestion is actionable next steps to resolve the issue
	Suggestion string
	// Links is an optional list of reference links
	Links []ErrorLink
}

ErrorWithSuggestion is a custom error type that includes user-friendly messaging. It wraps an original error with a human-readable message, actionable suggestion, and optional reference links.

func (*ErrorWithSuggestion) Error

func (es *ErrorWithSuggestion) Error() string

Error returns the error message

func (*ErrorWithSuggestion) Unwrap

func (es *ErrorWithSuggestion) Unwrap() error

Unwrap returns the wrapped error

type HandlerResolver

type HandlerResolver func(name string) (ErrorHandler, error)

HandlerResolver resolves named ErrorHandler instances. Typically backed by the IoC container.

type PatternMatcher

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

PatternMatcher handles matching error messages against patterns.

func NewPatternMatcher

func NewPatternMatcher() *PatternMatcher

NewPatternMatcher creates a new PatternMatcher instance.

func (*PatternMatcher) Match

func (m *PatternMatcher) Match(errorMessage string, patterns []string, useRegex bool) bool

Match checks if the given error message matches any of the patterns (OR logic).

When useRegex is false, patterns are matched as case-insensitive substrings. When useRegex is true, patterns are treated as regular expressions.

func (*PatternMatcher) MatchSingle

func (m *PatternMatcher) MatchSingle(value string, pattern string, useRegex bool) bool

MatchSingle checks if a single value matches a pattern.

When useRegex is false, the match is a case-insensitive substring check. When useRegex is true, the pattern is treated as a regular expression.

type ResourceNotAvailableHandler

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

ResourceNotAvailableHandler provides dynamic suggestions for resource availability errors by querying the ARM Providers API for supported regions.

func (*ResourceNotAvailableHandler) Handle

type ResourceTypeLocationResolver

type ResourceTypeLocationResolver interface {
	GetLocations(
		ctx context.Context,
		subscriptionID string,
		resourceType string,
	) ([]string, error)
}

ResourceTypeLocationResolver queries Azure for the locations where a given resource type is available.

type RuleLink struct {
	// URL is the link target (required)
	URL string `yaml:"url"`
	// Title is the display text (optional)
	Title string `yaml:"title,omitempty"`
}

RuleLink represents a reference link in a YAML rule.

Jump to

Keyboard shortcuts

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