result

package
v3.115.2 Latest Latest
Warning

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

Go to latest
Published: May 6, 2024 License: Apache-2.0 Imports: 5 Imported by: 10

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func BailError added in v3.80.0

func BailError(err error) error

BailError is the replacement for Result now that Go supports wrapping errors. It is used to indicate that a computation failed, but that it failed gracefully, i.e. it is not a bug in Pulumi. BailError implements the error interface but will prefix it's error string with BAIL, which if ever seen in user facing messages indicates that a check for bailing was missed. It also blocks `Unwrap` calls, instead to get access to the inner error use the `IsBail` function.

func BailErrorf added in v3.80.0

func BailErrorf(format string, args ...interface{}) error

BailErrorf is a helper for BailError(fmt.Errorf(...)).

func FprintBailf added in v3.80.0

func FprintBailf(w io.Writer, msg string, args ...any) error

FprintBailf writes a formatted string to the given writer and returns a BailError with the same message.

func IsBail added in v3.80.0

func IsBail(err error) bool

IsBail reports whether any error in err's tree is a `BailError`.

func TODO

func TODO() error

TODO returns an error that can be used in places that have not yet been adapted to use Results. Their use is intended to be temporary until Results are plumbed throughout the Pulumi codebase.

Types

type Result

type Result interface {
	Error() error
	IsBail() bool
}

Result represents the result of a computation that can fail. The Result type revolves around two notions of failure:

1. Computations can fail, but they can fail gracefully. Computations that fail gracefully do so by logging a diagnostic and returning a non-nil "bail" result.

2. Computations can fail due to bugs in Pulumi. Computations that fail in this manner do so by constructing a Result using the `Error`, `Errorf`, or `FromError` constructor functions.

Result is an interface so that it can be nullable. A function returning a pointer Result has the following semantics:

  • If the result is `nil`, the caller should proceed. The callee believes that the overarching plan can still continue, even if it logged diagnostics.

  • If the result is non-nil, the caller should not proceed. Most often, the caller should return this Result to its caller.

At the highest level, when a function wishes to return only an `error`, the `Error` member function can be used to turn a nullable `Result` into an `error`.

func Bail

func Bail() Result

Bail produces a Result that represents a computation that failed to complete successfully but is not a bug in Pulumi.

func Error

func Error(msg string) Result

Error produces a Result that represents an internal Pulumi error, constructed from the given message.

func Errorf

func Errorf(msg string, args ...interface{}) Result

Errorf produces a Result that represents an internal Pulumi error, constructed from the given format string and arguments.

func FromError

func FromError(err error) Result

FromError produces a Result that wraps an internal Pulumi error. Do not call this with a 'nil' error. A 'nil' error means that there was no problem, and in that case a 'nil' result should be used instead. If this is called with an error from `BailError` it will discard the inner error of that and return a bail result.

func Merge

func Merge(res1 Result, res2 Result) Result

Merge combines two results into one final result. It properly respects all three forms of Result (i.e. nil/bail/error) for both results, and combines all sensibly into a final form that represents the information of both.

func WrapIfNonNil

func WrapIfNonNil(err error) Result

WrapIfNonNil returns a non-nil Result if [err] is non-nil. Otherwise it returns nil.

Jump to

Keyboard shortcuts

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