utils

package
v0.1.2 Latest Latest
Warning

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

Go to latest
Published: Aug 2, 2025 License: GPL-3.0 Imports: 10 Imported by: 0

Documentation

Overview

Package utils provides common utility functions for the GitCells application.

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func GetLogFilePath

func GetLogFilePath() string

GetLogFilePath returns the path where log files are stored

func LogError

func LogError(logger *logrus.Logger, err error, operation string, context map[string]interface{})

LogError logs an error with appropriate context

func LogErrorDefault

func LogErrorDefault(err error, message string, fields map[string]interface{})

LogErrorDefault logs an error using the default logger

func LogErrorWithRetry

func LogErrorWithRetry(logger *logrus.Logger, err error, attempt, maxAttempts int)

LogErrorWithRetry logs an error with retry context

func LogInfo

func LogInfo(message string, fields map[string]interface{})

LogInfo logs an info message using the default logger

func LogModeChange

func LogModeChange(fromMode, toMode string)

LogModeChange logs when the user changes TUI modes

func LogUserAction

func LogUserAction(action string, fields map[string]interface{})

LogUserAction logs user actions in the TUI

func LogValidationError

func LogValidationError(field string, value interface{}, reason string)

LogValidationError logs validation errors with context

func LogWarn

func LogWarn(message string, fields map[string]interface{})

LogWarn logs a warning using the default logger

func LoggerWithFields

func LoggerWithFields(logger *logrus.Logger, fields logrus.Fields) *logrus.Entry

LoggerWithFields returns a logger with multiple fields set

func LoggerWithFile

func LoggerWithFile(logger *logrus.Logger, file string) *logrus.Entry

LoggerWithFile creates a logger with file context

func LoggerWithOperation

func LoggerWithOperation(logger *logrus.Logger, operation string) *logrus.Entry

LoggerWithOperation creates a logger with operation context

func NewLogger

func NewLogger(config *LogConfig) *logrus.Logger

NewLogger creates a new configured logger instance

func NewVerboseLogger

func NewVerboseLogger() *logrus.Logger

NewVerboseLogger creates a logger for verbose mode

func Retry

func Retry(operation RetryableOperation, config *RetryConfig) error

Retry executes an operation with retry logic

func RotateLogFile

func RotateLogFile(maxSizeBytes int64) error

RotateLogFile rotates the log file if it exceeds the maximum size

Types

type ErrorCollector

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

ErrorCollector collects multiple errors and provides a summary

func NewErrorCollector

func NewErrorCollector(limit int) *ErrorCollector

NewErrorCollector creates a new error collector with optional limit

func (*ErrorCollector) Add

func (ec *ErrorCollector) Add(err error)

Add adds an error to the collection

func (*ErrorCollector) AddContext

func (ec *ErrorCollector) AddContext(err error, context string)

AddContext adds an error with additional context

func (*ErrorCollector) Count

func (ec *ErrorCollector) Count() int

Count returns the number of collected errors

func (*ErrorCollector) Error

func (ec *ErrorCollector) Error() string

Error implements the error interface, providing a summary of all errors

func (*ErrorCollector) Errors

func (ec *ErrorCollector) Errors() []error

Errors returns all collected errors

func (*ErrorCollector) First

func (ec *ErrorCollector) First() error

First returns the first error, or nil if none

func (*ErrorCollector) HasErrors

func (ec *ErrorCollector) HasErrors() bool

HasErrors returns true if any errors were collected

type ErrorContextHook

type ErrorContextHook struct{}

ErrorContextHook adds error context to log entries

func (*ErrorContextHook) Fire

func (hook *ErrorContextHook) Fire(entry *logrus.Entry) error

Fire is called when a log entry is made

func (*ErrorContextHook) Levels

func (hook *ErrorContextHook) Levels() []logrus.Level

Levels returns the log levels this hook should fire for

type ErrorType

type ErrorType string

ErrorType represents different categories of errors

const (
	ErrorTypeConverter  ErrorType = "CONVERTER"
	ErrorTypeGit        ErrorType = "GIT"
	ErrorTypeWatcher    ErrorType = "WATCHER"
	ErrorTypeConfig     ErrorType = "CONFIG"
	ErrorTypeValidation ErrorType = "VALIDATION"
	ErrorTypeFileSystem ErrorType = "FILESYSTEM"
	ErrorTypeNetwork    ErrorType = "NETWORK"
	ErrorTypeConflict   ErrorType = "CONFLICT"
	ErrorTypePermission ErrorType = "PERMISSION"
	ErrorTypeCorruption ErrorType = "CORRUPTION"
)

type GitCellsError

type GitCellsError struct {
	Type        ErrorType
	Operation   string
	File        string
	Cause       error
	Message     string
	Recoverable bool
}

GitCellsError represents a custom error type for GitCells operations

func NewError

func NewError(errorType ErrorType, operation, message string) *GitCellsError

NewError creates a new GitCellsError

func WrapError

func WrapError(err error, errorType ErrorType, operation, message string) *GitCellsError

WrapError wraps an existing error with GitCells context

func WrapFileError

func WrapFileError(err error, errorType ErrorType, operation, file, message string) *GitCellsError

WrapFileError wraps an error with file context

func (*GitCellsError) Error

func (e *GitCellsError) Error() string

Error implements the error interface

func (*GitCellsError) IsRecoverable

func (e *GitCellsError) IsRecoverable() bool

IsRecoverable returns whether the error is recoverable

func (*GitCellsError) Unwrap

func (e *GitCellsError) Unwrap() error

Unwrap returns the underlying error

type GitCellsFormatter

type GitCellsFormatter struct {
	DisableColors   bool
	FullTimestamp   bool
	TimestampFormat string
	AddSource       bool
}

GitCellsFormatter is a custom formatter for GitCells

func (*GitCellsFormatter) Format

func (f *GitCellsFormatter) Format(entry *logrus.Entry) ([]byte, error)

Format implements the logrus.Formatter interface

type LogConfig

type LogConfig struct {
	Level     LogLevel
	Format    LogFormat
	Output    io.Writer
	File      string
	MaxSize   int64 // Max file size in bytes
	MaxAge    int   // Max age in days
	AddSource bool  // Add source file and line
	NoColors  bool  // Disable colors in text format
}

LogConfig configures logger behavior

func DefaultLogConfig

func DefaultLogConfig() *LogConfig

DefaultLogConfig returns sensible defaults

type LogFormat

type LogFormat string

LogFormat represents different log output formats

const (
	LogFormatText LogFormat = "text"
	LogFormatJSON LogFormat = "json"
)

type LogLevel

type LogLevel string

LogLevel represents different log levels

const (
	LogLevelTrace LogLevel = "trace"
	LogLevelDebug LogLevel = "debug"
	LogLevelInfo  LogLevel = "info"
	LogLevelWarn  LogLevel = "warn"
	LogLevelError LogLevel = "error"
	LogLevelFatal LogLevel = "fatal"
)

type Progress

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

Progress represents a progress tracker for logging

func NewProgress

func NewProgress(logger *logrus.Logger, name string, total int) *Progress

NewProgress creates a new progress tracker

func (*Progress) Finish

func (p *Progress) Finish()

Finish marks the progress as complete

func (*Progress) Update

func (p *Progress) Update(done int)

Update updates the progress and logs if significant progress was made

type RetryConfig

type RetryConfig struct {
	MaxAttempts int
	ShouldRetry func(error) bool
	OnRetry     func(error, int)
}

RetryConfig configures retry behavior

func DefaultRetryConfig

func DefaultRetryConfig() *RetryConfig

DefaultRetryConfig returns a sensible default retry configuration

type RetryableOperation

type RetryableOperation func() error

RetryableOperation represents an operation that can be retried

type ValidationError

type ValidationError struct {
	Field   string
	Value   interface{}
	Message string
}

ValidationError represents a validation error with field context

func (*ValidationError) Error

func (v *ValidationError) Error() string

Error implements the error interface

type ValidationErrors

type ValidationErrors []ValidationError

ValidationErrors represents multiple validation errors

func (*ValidationErrors) Add

func (ve *ValidationErrors) Add(field string, value interface{}, message string)

Add adds a validation error

func (ValidationErrors) Error

func (ve ValidationErrors) Error() string

Error implements the error interface

func (ValidationErrors) HasErrors

func (ve ValidationErrors) HasErrors() bool

HasErrors returns true if there are validation errors

Jump to

Keyboard shortcuts

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