feat: Change stack trace format to match runtime.Stack#5
Merged
Conversation
Changed the default stack frame formatter to match the format used by
runtime.Stack() for better consistency with Go's standard stack traces.
Old format:
file.go:123 (0x456)
functionName: sourceCodeLine
New format:
functionName()
file.go:123 +0x456
Benefits:
- Matches runtime.Stack() format exactly
- No dependency on source file availability at runtime
- Cleaner and more concise output
- Function names always visible (previously only shown with source)
Changes:
- Updated defaultStackFrameFormatter to new format
- Removed source code line reading from default formatter
- Updated all README examples to show new format
- All tests pass with new format
🤖 Generated with [Claude Code](https://claude.com/claude-code)
Co-Authored-By: Claude <noreply@anthropic.com>
Package names were missing from stack trace function names. This fix concatenates Package and Name fields to show the full qualified function name, matching runtime.Stack() output format. Example output: - Before: (*Repository).Get() - After: main.(*Repository).Get()
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Summary
Changed the default stack frame formatter to match
runtime.Stack()format for better consistency with Go's standard stack traces and to eliminate dependency on source file availability at runtime.Old Format vs New Format
Old format (required source files at runtime):
New format (runtime.Stack compatible):
Motivation
The old format had a significant limitation: it attempted to read source files at runtime using
os.Open()to display the actual source code line. This caused issues in production environments where:Example of the problem:
Notice: No function names or source code lines are visible because the source files weren't available in the deployed environment.
Benefits of New Format
1. Consistent Output
Function names are always displayed, regardless of source file availability:
2. Runtime.Stack Compatibility
Matches the exact format used by Go's
runtime/debug.Stack(), making it familiar to all Go developers and compatible with existing log parsing tools.3. No Runtime Dependencies
No longer attempts to read source files at runtime - all information comes from the compiled binary's debug symbols.
4. Cleaner Output
More concise format that's easier to read in logs:
Changes
Code Changes
stackframe_formatter.go:
README.md:
Example Output
Before (in production, source unavailable):
After:
Testing
All existing tests pass with the new format:
$ go test ./... ok github.com/tomoemon/go-errstk 0.276s ok github.com/tomoemon/go-errstk/errstklint 0.667sBackwards Compatibility
This is a format change that affects the string representation of stack traces. Users who:
DefaultStackFrameFormatterif they need the old behaviorWalkStack()API for custom formatting🤖 Generated with Claude Code