diag

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2026 License: MIT Imports: 9 Imported by: 1 module, 0 packages

The first number is the count of modules that contain a package that imports this one. The module count is a better indicator of popularity than the package count. A module with 100 importing packages is counted only once instead of 100 times, reflecting the fact that the choice to use the package was likely made only once, not 100 times.
A '?' means that the value hasn't been computed yet.

Documentation

Overview

Package diag records crash reports and optional routine debug traces. It is deliberately stdlib-only so any layer may import it, and it records a short operation label rather than raw arguments, so a report never contains a secret.

Index

Constants

View Source
const (
	CrashFile = "crash.log"
	DebugFile = "debug.log"
)

The file names under the configuration directory.

View Source
const Header = "=== nova crash report ==="

Header marks the start of a crash report so a viewer can find the most recent one in an appended file.

Variables

This section is empty.

Functions

func Catch

func Catch(op string)

Catch recovers a panic in the calling goroutine and records it with the default recorder. With no recorder it prints a one-line error to stderr, so a panic is never silent. Use it as `defer diag.Catch("operation")`.

func LatestReport

func LatestReport(data []byte) []byte

LatestReport returns the last crash report in data, or data unchanged when it holds no report marker.

func Report

func Report(v any, op string) (string, error)

Report records a panic through the default recorder and returns the crash file path. It is the package-level form of Recorder.Report for code that has no recorder to hand.

func SetDebug

func SetDebug(on bool)

SetDebug turns routine tracing on the default recorder on or off, if any.

func SetDefault

func SetDefault(r *Recorder)

SetDefault installs the process-wide recorder. Passing nil clears it.

func SetMode

func SetMode(mode string)

SetMode records the active mode on the default recorder, if any.

func SetModel

func SetModel(model string)

SetModel records the active model on the default recorder, if any.

func SetOp

func SetOp(op string)

SetOp records the last operation on the default recorder, if any. The package-level setters keep callers from branching on a nil recorder.

func Tracef

func Tracef(format string, args ...any)

Tracef writes a routine trace line through the default recorder when it has debug on. It is a no-op otherwise.

Types

type Options

type Options struct {
	Dir     string
	Version string
	Mode    string
	Model   string
	Debug   bool
	// MaxBytes is how large a log may grow before it moves aside to <name>.1; zero
	// means 4 MiB.
	MaxBytes int64

	// Now and Stack are seams for tests.
	Now   func() time.Time
	Stack func() []byte
}

Options configures a Recorder. Dir, when set, is the directory that holds CrashFile and DebugFile; when empty, reports cannot be written.

type Recorder

type Recorder struct {
	// contains filtered or unexported fields
}

Recorder writes crash reports and, when debug is on, routine trace lines. It is safe for concurrent use, because the agent loop, the provider, and the extension host all run on their own goroutines.

func Default

func Default() *Recorder

Default returns the process-wide recorder, or nil before startup sets one.

func New

func New(opt Options) *Recorder

New builds a Recorder. The zero Options is valid: it records nothing and is useful only to keep callers from branching on nil.

func (*Recorder) Catch

func (r *Recorder) Catch(op string)

Catch recovers a panic in the calling goroutine and records it with this Recorder. Use it as `defer r.Catch("operation")` at the top of a goroutine.

func (*Recorder) Close

func (r *Recorder) Close() error

Close releases the debug file, if one is open.

func (*Recorder) CrashPath

func (r *Recorder) CrashPath() string

CrashPath is the crash file path, or empty when no directory was configured.

func (*Recorder) DebugPath

func (r *Recorder) DebugPath() string

DebugPath is the debug file path, or empty when no directory was configured.

func (*Recorder) Debugf

func (r *Recorder) Debugf(format string, args ...any)

Debugf appends a timestamped trace line when debug is on. It never creates the debug file until the first line is written.

func (*Recorder) Report

func (r *Recorder) Report(v any, op string) (string, error)

Report formats and appends one crash report and returns the file path, so the caller can tell the user where to look. op overrides any operation set with SetOp; when empty, the last operation is used.

func (*Recorder) SetDebug

func (r *Recorder) SetDebug(on bool)

SetDebug turns routine tracing on or off.

func (*Recorder) SetMode

func (r *Recorder) SetMode(mode string)

SetMode records the active mode for the next crash report.

func (*Recorder) SetModel

func (r *Recorder) SetModel(model string)

SetModel records the active model for the next crash report.

func (*Recorder) SetOp

func (r *Recorder) SetOp(op string)

SetOp records the last operation for the next crash report.

Jump to

Keyboard shortcuts

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