https://github.com/rahugg/go-stacktrace
go-stacktrace is a lightweight and customizable Go package for enhanced error handling and tracing. It wraps errors with additional context, user-friendly messages, and detailed stack traces, making it easier to diagnose and debug issues in your Go applications.
https://github.com/rahugg/go-stacktrace
error-handling error-traces golang golang-package golang-tools lightweight traceroute tracing-library zero-dependency
Last synced: about 1 month ago
JSON representation
go-stacktrace is a lightweight and customizable Go package for enhanced error handling and tracing. It wraps errors with additional context, user-friendly messages, and detailed stack traces, making it easier to diagnose and debug issues in your Go applications.
- Host: GitHub
- URL: https://github.com/rahugg/go-stacktrace
- Owner: Rahugg
- License: mit
- Created: 2024-11-22T12:00:19.000Z (11 months ago)
- Default Branch: master
- Last Pushed: 2024-11-22T14:49:21.000Z (11 months ago)
- Last Synced: 2025-04-02T15:51:14.367Z (6 months ago)
- Topics: error-handling, error-traces, golang, golang-package, golang-tools, lightweight, traceroute, tracing-library, zero-dependency
- Language: Go
- Homepage:
- Size: 7.81 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: Readme.md
- License: LICENSE
Awesome Lists containing this project
README
# go-stacktrace
`go-stacktrace` is a robust Go package for enhanced error handling, providing stack traces, error wrapping, and user-friendly error messages with optional color formatting.
## Features
- ๐ Detailed stack traces for improved debugging
- ๐ Custom user messages and payload support
- ๐จ Colorized error output (configurable)
- ๐ Error wrapping with context preservation
- ๐ชถ Lightweight with zero external dependencies
- ๐งช Comprehensive test coverage## Installation
```bash
go get github.com/Rahugg/go-stacktrace
```## Usage
### Basic Error Wrapping
```go
import "github.com/Rahugg/go-stacktrace/errorhandler"func main() {
err := someFunction()
if err != nil {
wrappedErr := errorhandler.WrapError(
err,
"operation-failed", // payload
"Failed to process request" // user message
)
fmt.Println(errorhandler.FailOnError(wrappedErr))
}
}
```### Controlling Color Output
```go
// Disable colored output
errorhandler.SetEnableColors(false)// Enable colored output (default)
errorhandler.SetEnableColors(true)
```### Error Information
The wrapped error includes:
- Original error message
- User-friendly message
- Custom payload (optional)
- Stack trace
- Color-coded output (optional)## Example Output
```
Payload: operation-failed
Error Details
Original Error: file not found
User Message: Failed to process requestStack Trace
main.someFunction
/path/to/file.go:25
main.main
/path/to/main.go:12
```## Features in Detail
### TracedError Structure
```go
type TracedError struct {
OriginalError error
UserMessage string
Payload string
StackTrace []uintptr
}
```### Available Colors
- Red: Error messages
- Green: User messages
- Yellow: Payload information
- Blue: Function names in stack trace
- Magenta: Stack trace headers
- Cyan: Section headers## Contributing
Contributions are welcome! Please feel free to submit a Pull Request.
Or DM me.## License
This project is licensed under the MIT License - see the LICENSE file for details.
## Project Structure
```
.
โโโ errorhandler
โ โโโ colors.go # Color constants
โ โโโ errorhandler.go # Core functionality
โ โโโ errorhandler_test.go # Test suite
โโโ example
โ โโโ main.go # Usage examples
โโโ go.mod
โโโ go.yml
โโโ README.md
```