Fix test failures on Linux x64 by preventing function inlining#1
Merged
Conversation
Add //go:noinline directives to ensure consistent stack frame structure across different architectures and compiler versions. The issue occurred because Go compiler's inline optimization was inconsistent between macOS (ARM64) and Linux (x64), causing runtime.Callers to skip different numbers of frames and miss the test file names in stack traces. Changes: - Add //go:noinline to Wrap, With, innerWithStack, and callers - Improve error messages in tests to show actual output on failure This ensures stack traces consistently capture the correct caller information regardless of the build environment. 🤖 Generated with [Claude Code](https://claude.com/claude-code) Co-Authored-By: Claude <noreply@anthropic.com>
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.
Problem
Tests were passing on macOS (ARM64) but failing on GitHub Actions (Linux x64). The root cause was inconsistent function inlining by the Go compiler across different architectures and compiler versions.
When functions like
With,innerWithStack, andcallerswere inlined, the stack frame count changed, causingruntime.Callersto skip different numbers of frames. This resulted in test file names (error_test.go) missing from stack traces on Linux.Solution
Added
//go:noinlinedirectives to the following functions to ensure consistent stack frame structure:WrapWithinnerWithStackcallersThis guarantees that
runtime.Callerswithskip=4consistently captures the correct caller information regardless of the build environment.Changes
//go:noinlineto critical stack trace capture functionsTesting
Performance Impact
Negligible (<0.2%). The overhead of preventing inlining is insignificant compared to the cost of
runtime.Callers()and stack trace generation, which are already heavy operations only executed in error paths.