Skip to content

Commit

Permalink
Implement PluginErrorf (#1228)
Browse files Browse the repository at this point in the history
  • Loading branch information
fabrizio-grafana authored Feb 13, 2025
1 parent 57415c7 commit a29bee2
Show file tree
Hide file tree
Showing 2 changed files with 12 additions and 0 deletions.
6 changes: 6 additions & 0 deletions backend/error_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -64,6 +64,12 @@ func DownstreamErrorf(format string, a ...any) error {
return DownstreamError(fmt.Errorf(format, a...))
}

// PluginErrorf creates a new error with status [ErrorSourcePlugin] and formats
// according to a format specifier and returns the string as a value that satisfies error.
func PluginErrorf(format string, a ...any) error {
return PluginError(fmt.Errorf(format, a...))
}

// ErrorSourceFromContext returns the error source stored in the context.
// If no error source is stored in the context, [DefaultErrorSource] is returned.
func ErrorSourceFromContext(ctx context.Context) ErrorSource {
Expand Down
6 changes: 6 additions & 0 deletions experimental/status/status_source.go
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,12 @@ func DownstreamErrorf(format string, a ...any) error {
return DownstreamError(fmt.Errorf(format, a...))
}

// PluginErrorf creates a new error with status [ErrorSourcePlugin] and formats
// according to a format specifier and returns the string as a value that satisfies error.
func PluginErrorf(format string, a ...any) error {
return PluginError(fmt.Errorf(format, a...))
}

func (e ErrorWithSource) ErrorSource() Source {
return e.source
}
Expand Down

0 comments on commit a29bee2

Please sign in to comment.