crashdump

package
v1.26.5 Latest Latest
Warning

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

Go to latest
Published: Feb 28, 2026 License: MIT Imports: 19 Imported by: 0

Documentation

Overview

Package crashdump provides crash dump functionality for klaudiush.

Index

Constants

View Source
const (
	// FilePerm is the file permission for crash dump files.
	FilePerm fs.FileMode = 0o600

	// DirPerm is the directory permission for crash dump directories.
	DirPerm fs.FileMode = 0o700

	// FileExtension is the extension for crash dump files.
	FileExtension = ".json"

	// TempSuffix is the suffix for temporary files during atomic writes.
	TempSuffix = ".tmp"
)

Variables

View Source
var (
	// ErrDumpNotFound is returned when a crash dump is not found.
	ErrDumpNotFound = errors.New("crash dump not found")

	// ErrStorageNotInitialized is returned when storage is not initialized.
	ErrStorageNotInitialized = errors.New("storage not initialized")
)
View Source
var (
	// ErrWriteFailed is returned when writing a crash dump fails.
	ErrWriteFailed = errors.New("failed to write crash dump")

	// ErrInvalidDumpDir is returned when the dump directory is invalid.
	ErrInvalidDumpDir = errors.New("invalid dump directory")
)

Functions

This section is empty.

Types

type Collector

type Collector interface {
	// Collect gathers crash information from a recovered panic.
	Collect(recovered any, ctx *hook.Context, cfg *config.Config) *CrashInfo
}

Collector collects crash diagnostic information.

type ContextInfo

type ContextInfo struct {
	// EventType is the type of hook event (PreToolUse, PostToolUse, Notification).
	EventType string `json:"event_type"`

	// ToolName is the name of the tool being invoked.
	ToolName string `json:"tool_name"`

	// Command is the command being executed (for Bash tool).
	Command string `json:"command,omitempty"`

	// FilePath is the file path (for file operations).
	FilePath string `json:"file_path,omitempty"`
}

ContextInfo contains the hook context at the time of crash.

type CrashInfo

type CrashInfo struct {
	// ID is the unique identifier for this crash dump.
	ID string `json:"id"`

	// Timestamp is when the crash occurred.
	Timestamp time.Time `json:"timestamp"`

	// PanicValue is the value passed to panic().
	PanicValue string `json:"panic_value"`

	// StackTrace is the stack trace of the panicking goroutine.
	StackTrace string `json:"stack_trace"`

	// Runtime contains runtime information at the time of crash.
	Runtime RuntimeInfo `json:"runtime"`

	// Context contains the hook context if available.
	Context *ContextInfo `json:"context,omitempty"`

	// Config contains a sanitized config snapshot.
	Config map[string]any `json:"config,omitempty"`

	// Metadata contains additional diagnostic information.
	Metadata DumpMetadata `json:"metadata"`
}

CrashInfo contains all diagnostic information about a crash.

type DefaultCollector

type DefaultCollector struct {
	// Version is the klaudiush version.
	Version string
	// contains filtered or unexported fields
}

DefaultCollector is the default crash info collector.

func NewCollector

func NewCollector(version string) *DefaultCollector

NewCollector creates a new crash info collector.

func (*DefaultCollector) Collect

func (c *DefaultCollector) Collect(
	recovered any,
	ctx *hook.Context,
	cfg *config.Config,
) *CrashInfo

Collect gathers crash information from a recovered panic.

type DumpMetadata

type DumpMetadata struct {
	// Version is the klaudiush version.
	Version string `json:"version"`

	// User is the username who triggered the crash.
	User string `json:"user,omitempty"`

	// Hostname is the machine hostname.
	Hostname string `json:"hostname,omitempty"`

	// WorkingDir is the current working directory.
	WorkingDir string `json:"working_dir,omitempty"`
}

DumpMetadata contains additional context about the crash dump.

type DumpSummary

type DumpSummary struct {
	// ID is the unique identifier for this crash dump.
	ID string `json:"id"`

	// Timestamp is when the crash occurred.
	Timestamp time.Time `json:"timestamp"`

	// PanicValue is a truncated version of the panic value.
	PanicValue string `json:"panic_value"`

	// FilePath is the path to the dump file.
	FilePath string `json:"file_path"`

	// Size is the size of the dump file in bytes.
	Size int64 `json:"size"`
}

DumpSummary provides a short summary for listing crash dumps.

type FilesystemStorage

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

FilesystemStorage implements Storage using the local filesystem.

func NewFilesystemStorage

func NewFilesystemStorage(dumpDir string) (*FilesystemStorage, error)

NewFilesystemStorage creates a new filesystem-based storage.

func (*FilesystemStorage) Delete

func (s *FilesystemStorage) Delete(id string) error

Delete removes a crash dump by ID.

func (*FilesystemStorage) Exists

func (s *FilesystemStorage) Exists() bool

Exists checks if the storage directory exists.

func (*FilesystemStorage) Get

func (s *FilesystemStorage) Get(id string) (*CrashInfo, error)

Get retrieves a crash dump by ID.

func (*FilesystemStorage) GetDumpDir

func (s *FilesystemStorage) GetDumpDir() string

GetDumpDir returns the dump directory path.

func (*FilesystemStorage) Initialize

func (s *FilesystemStorage) Initialize() error

Initialize creates the storage directory if it doesn't exist.

func (*FilesystemStorage) List

func (s *FilesystemStorage) List() ([]DumpSummary, error)

List returns all crash dump summaries, sorted by timestamp (newest first).

func (*FilesystemStorage) Prune

func (s *FilesystemStorage) Prune(maxDumps int, maxAge time.Duration) (int, error)

Prune removes old dumps based on max count and max age. Returns the number of dumps removed.

type FilesystemWriter

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

FilesystemWriter writes crash dumps to the filesystem.

func NewFilesystemWriter

func NewFilesystemWriter(dumpDir string) (*FilesystemWriter, error)

NewFilesystemWriter creates a new filesystem-based writer.

func (*FilesystemWriter) GetDumpDir

func (w *FilesystemWriter) GetDumpDir() string

GetDumpDir returns the dump directory path.

func (*FilesystemWriter) Write

func (w *FilesystemWriter) Write(info *CrashInfo) (string, error)

Write writes a crash dump and returns the file path.

type RuntimeInfo

type RuntimeInfo struct {
	// GOOS is the operating system (e.g., "darwin", "linux").
	GOOS string `json:"goos"`

	// GOARCH is the architecture (e.g., "amd64", "arm64").
	GOARCH string `json:"goarch"`

	// GoVersion is the Go version used to build the binary.
	GoVersion string `json:"go_version"`

	// NumGoroutine is the number of goroutines at crash time.
	NumGoroutine int `json:"num_goroutine"`

	// NumCPU is the number of CPUs available.
	NumCPU int `json:"num_cpu"`
}

RuntimeInfo contains Go runtime information at the time of crash.

type Sanitizer

type Sanitizer struct{}

Sanitizer handles config sanitization for crash dumps.

func NewSanitizer

func NewSanitizer() *Sanitizer

NewSanitizer creates a new config sanitizer.

func (*Sanitizer) SanitizeConfig

func (s *Sanitizer) SanitizeConfig(cfg *config.Config) map[string]any

SanitizeConfig converts config to a map and removes sensitive values.

type Storage

type Storage interface {
	// List returns all crash dump summaries, sorted by timestamp (newest first).
	List() ([]DumpSummary, error)

	// Get retrieves a crash dump by ID.
	Get(id string) (*CrashInfo, error)

	// Delete removes a crash dump by ID.
	Delete(id string) error

	// Prune removes old dumps based on max count and max age.
	Prune(maxDumps int, maxAge time.Duration) (int, error)

	// Exists checks if the storage directory exists.
	Exists() bool

	// Initialize creates the storage directory if it doesn't exist.
	Initialize() error
}

Storage provides operations for managing crash dumps.

type Writer

type Writer interface {
	// Write writes a crash dump and returns the file path.
	Write(info *CrashInfo) (string, error)
}

Writer writes crash dumps to storage.

Jump to

Keyboard shortcuts

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