warnonerror

package
v0.1.75 Latest Latest
Warning

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

Go to latest
Published: Sep 27, 2024 License: Apache-2.0 Imports: 2 Imported by: 15

README

Package containing custom versions of common functions/methods that always log a warning in case of error.

Close wraps a resource.Close() call and logs the error, if any, adding a custom message.

This function is intended to be used as a better alternative to completely ignoring an error in cases where there isn't any obvious reason to handle it explicitly. Also, adding a custom message around the error allows to easily find any instances of this in our log files.

It can be used in a defer statement, e.g.:

defer warnonerror.Close(resource, "Warning: ignoring error")

Documentation

Overview

Package warnonerror contains custom versions of common functions/methods that always log a warning in case of error.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func Close

func Close(c io.Closer, msg string) error

Close wraps a resource.Close() call and logs the error, if any, adding a custom message.

This function is intended to be used as a better alternative to completely ignoring an error in cases where there isn't any obvious reason to handle it explicitly.

Its allows to turn ugly error-logging code such as:

defer func() {
    err := resource.Close()
    if err != nil {
        log.Printf("Warning: ignoring error (%v)", err)
    }
}()

into a simplified pattern of:

defer warnonerror.Close(resource, "Warning: ignoring error")

Types

This section is empty.

Jump to

Keyboard shortcuts

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