util

package
v0.0.0-...-6e5b399 Latest Latest
Warning

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

Go to latest
Published: Feb 22, 2025 License: BSD-3-Clause Imports: 3 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func PanicIf

func PanicIf(condition bool, message string, args ...interface{})

PanicIf will panic with a custom error if a condition is true.

In fakes and tests, it is often desirable to panic when some precondition is violated to provide a loud indication that something wasn't set correctly. PanicIf allows for panicking in those situations without having to introduce uncovered conditional code and/or adding tests to cover those situations.

This should be limited to test code and fakes. The code for the actual binary should use proper error handling.

func PanicOnError

func PanicOnError(err error)

PanicOnError will panic if err is not nil.

Specific error types will have additional information added to the panic e.g. the stderr of a failed process will be included in the panic in the case of *exec.ExitError.

In fakes and tests, it is often desirable to panic rather than returning an error (e.g. the fake data is in an inconsistent state or a function should always succeed) because the situation isn't one where the errors should be handled. PanicOnError allows for panicking in those situations without having to introduce uncovered conditional code and/or adding tests to cover those situations.

This should be limited to test code and fakes. The code for the actual binary should use proper error handling.

Types

This section is empty.

Jump to

Keyboard shortcuts

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