debug

package
v0.1.6 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 2024 License: MIT Imports: 5 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func LogSeq

func LogSeq(logger *log.Logger, title string, seq iter.Seq[string]) error

LogSeq prints a title and a sequence of strings. Each element of the sequence is written in a new line.

However, only the title uses the logger's flags since the sequence itself uses logger.Writer() writer instead.

Parameters:

  • logger: The logger to use.
  • title: The title to print.
  • seq: The sequence to print.

Returns:

  • error: An error if printing failed.

Errors:

  • errors.ErrNilParameter: when the logger is nil.
  • ErrPrintFailed: when the logger failed to print an element.

Behaviors:

  • Prints the title if it is not empty. Same goes for seq when it is nil.
  • To add an empty line at the end, use _ = yield("\n") in seq.

func NewErrPrintFailed

func NewErrPrintFailed(idx int, reason error) error

NewErrPrintFailed creates a new ErrPrintFailed error.

Parameters:

  • idx: The index of the element that failed to print.
  • reason: The reason for the failure.

Returns:

  • error: The new error. Never returns nil.

Format:

"could not print the <ordinal> element: <reason>"

Where: - <ordinal>: The ordinal of the index + 1 according to humanize.Ordinal - <reason>: The reason for the failure. If nil, "something went wrong" is used instead.

Types

type ErrPrintFailed

type ErrPrintFailed struct {
	// Idx is the index of the element that failed to print.
	Idx int

	// Reason is the reason for the failure.
	Reason error
}

ErrPrintFailed is an error that is returned when printing failed.

func (ErrPrintFailed) Error

func (e ErrPrintFailed) Error() string

Error implements the error interface.

Jump to

Keyboard shortcuts

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