Documentation
¶
Index ¶
- Constants
- Variables
- func AddEnrich(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostics, ...)
- func AddError(ctx context.Context, diags *fwdiag.Diagnostics, err error, keyvals ...any)
- func AddOne(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostic, ...)
- func Append(ctx context.Context, diags sdkdiag.Diagnostics, err error, keyvals ...any) sdkdiag.Diagnostics
- func AppendEnrich(ctx context.Context, existing sdkdiag.Diagnostics, ...) sdkdiag.Diagnostics
- func AppendOne(ctx context.Context, existing sdkdiag.Diagnostics, incoming sdkdiag.Diagnostic, ...) sdkdiag.Diagnostics
- func Assert[T any](val T, err error) (T, error)
- func EnrichAppend(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostics, ...)deprecated
- func Errorf(format string, args ...any) error
- func NewError(err error) error
- func SetFS(fs FileSystem, baseDir string)
- func SetLogger(logger Logger)
- type ContextKey
- type Error
- type FileSystem
- type Logger
- type StdLogger
- func (l StdLogger) Debug(ctx context.Context, msg string, keyvals map[string]any)
- func (l StdLogger) Error(ctx context.Context, msg string, keyvals map[string]any)
- func (l StdLogger) Info(ctx context.Context, msg string, keyvals map[string]any)
- func (l StdLogger) Warn(ctx context.Context, msg string, keyvals map[string]any)
- type TFLogLogger
- func (l TFLogLogger) Debug(ctx context.Context, msg string, keyvals map[string]any)
- func (l TFLogLogger) Error(ctx context.Context, msg string, keyvals map[string]any)
- func (l TFLogLogger) Info(ctx context.Context, msg string, keyvals map[string]any)
- func (l TFLogLogger) Warn(ctx context.Context, msg string, keyvals map[string]any)
- type WrappedFS
Constants ¶
const ( ID = "id" ResourceName = "resource_name" ServiceName = "service_name" DiagnosticSummaryKey = "diagnostic_summary" DiagnosticDetailKey = "diagnostic_detail" ErrorSummaryKey = "error_summary" ErrorDetailKey = "error_detail" LogErrorKey = "log_error" LogWarnKey = "log_warn" LogInfoKey = "log_info" SeverityError = internal.SeverityError SeverityWarning = internal.SeverityWarning SeverityInfo = internal.SeverityInfo )
Variables ¶
var Debugf = internal.Debugf
Re-export internal.Debugf for internal debugging
var NewWrappedFS = internal.NewWrappedFS
Functions ¶
func AddEnrich ¶ added in v0.7.0
func AddEnrich(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostics, keyvals ...any)
AddEnrich is a plugin Framework helper function that enriches diagnostics with smarterr information. This will not change the severity of either incoming or existing diagnostics, but will change the summary and detail of _incoming_ diagnostics only with smarterr information. Mutates the diagnostics in place via pointer, matching the framework pattern.
Template usage:
- If you want to customize the output for framework-generated diagnostics (e.g., value conversion errors), define `diagnostic_summary` and `diagnostic_detail` templates in your config. These will be used by AddEnrich.
- If these templates are not defined, the original diagnostic summary and detail are used.
- Note: All output is a diagnostic; the template name refers to the input type (error vs. diagnostic).
func AddError ¶ added in v0.2.0
AddError adds a formatted error to Terraform Plugin Framework diagnostics. Mutates the diagnostics in place via pointer, matching the framework pattern.
Template usage:
- To customize the output for errors (Go error values), define `error_summary` and `error_detail` templates in your config.
- These templates control the summary and detail for diagnostics created from errors via AddError.
- If these templates are not defined, a fallback using the original error is used.
- Note: All output is a diagnostic; the template name refers to the input type (error vs. diagnostic).
func AddOne ¶ added in v0.7.0
func AddOne(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostic, keyvals ...any)
AddOne appends a single diagnostic to existing Framework diagnostics with enrichment
func Append ¶ added in v0.2.0
func Append(ctx context.Context, diags sdkdiag.Diagnostics, err error, keyvals ...any) sdkdiag.Diagnostics
Append adds a formatted error to Terraform Plugin SDK diagnostics and returns the updated diagnostics slice.
Template usage:
- To customize the output for errors (Go error values), define `error_summary` and `error_detail` templates in your config.
- These templates control the summary and detail for diagnostics created from errors via Append.
- If these templates are not defined, a fallback using the original error is used.
- Note: All output is a diagnostic; the template name refers to the input type (error vs. diagnostic).
func AppendEnrich ¶ added in v0.7.0
func AppendEnrich(ctx context.Context, existing sdkdiag.Diagnostics, incoming sdkdiag.Diagnostics, keyvals ...any) sdkdiag.Diagnostics
AppendEnrich appends incoming SDK diagnostics to existing SDK diagnostics with enrichment
func AppendOne ¶ added in v0.7.0
func AppendOne(ctx context.Context, existing sdkdiag.Diagnostics, incoming sdkdiag.Diagnostic, keyvals ...any) sdkdiag.Diagnostics
AppendOne appends a single diagnostic to existing SDK diagnostics with enrichment
func Assert ¶ added in v0.2.0
Assert wraps a call returning (T, error) with smarterr.NewError on failure. Go doesn't yet support generics-based tuple unpacking, so this form works well for now.
func EnrichAppend
deprecated
added in
v0.2.0
func EnrichAppend(ctx context.Context, existing *fwdiag.Diagnostics, incoming fwdiag.Diagnostics, keyvals ...any)
EnrichAppend is an alias for AddEnrich to maintain backward compatibility.
Deprecated: Use AddEnrich instead to align with Framework "Add" verb convention
func Errorf ¶ added in v0.2.0
Errorf formats according to a format specifier and returns a smarterr-enriched error. It behaves like fmt.Errorf, but also captures contextual metadata based on the call site. This ensures consistent DX and structured diagnostics with minimal developer effort.
Example:
return smarterr.Errorf("unexpected result for alarm %q", name)
func NewError ¶ added in v0.2.0
NewError wraps an existing error with smarterr metadata derived from the call stack. It automatically annotates the error with context-aware information (e.g., sub-action) without requiring developer input, reducing fragility and promoting consistent error enrichment.
Use NewError at the site where an error is first returned or recognized. The resulting error can be passed directly to smarterr.Append or smarterr.AddError without needing manual WithField-style annotation.
Example:
return nil, smarterr.NewError(err)
func SetFS ¶
func SetFS(fs FileSystem, baseDir string)
SetFS allows the host application to provide a FileSystem implementation and the base directory for path normalization.
Types ¶
type ContextKey ¶ added in v0.4.0
type ContextKey internal.ContextKey
type Error ¶ added in v0.2.0
type Error struct {
Err error // The original or wrapped error
Message string // Optional developer-provided message (from Errorf)
Annotations map[string]string // Arbitrary key-value annotations (e.g., subaction, resource_id)
CapturedStack []runtime.Frame // Captured call stack for stack matching
}
Error is the enriched smarterr error type. It wraps a base error and includes structured annotations that can be used by Append or AddError to construct clear, user-friendly diagnostics.
type FileSystem ¶
type FileSystem = internal.FileSystem
type Logger ¶
type Logger interface {
Debug(ctx context.Context, msg string, keyvals map[string]any)
Info(ctx context.Context, msg string, keyvals map[string]any)
Warn(ctx context.Context, msg string, keyvals map[string]any)
Error(ctx context.Context, msg string, keyvals map[string]any)
}
Logger is the interface for user-facing logs emitted by smarterr. These logs are intended for consumers of smarterr, not for internal debugging.
type StdLogger ¶
type StdLogger struct{}
StdLogger is an adapter that emits user-facing logs using the standard Go log package.