Skip to content

fix: prevent panic when pkg is nil in packageLine#564

Open
Yanhu007 wants to merge 1 commit intogotestyourself:mainfrom
Yanhu007:fix/packageline-nil-panic
Open

fix: prevent panic when pkg is nil in packageLine#564
Yanhu007 wants to merge 1 commit intogotestyourself:mainfrom
Yanhu007:fix/packageline-nil-panic

Conversation

@Yanhu007
Copy link
Copy Markdown

Fixes #413

Problem

When converting go test -bench output, Execution.Package() may return nil for packages that only have benchmark events (skip/fail actions without a preceding "start" that creates the Package entry). packageLine then panics on pkg.cached nil dereference.

Fix

Add a nil check for pkg at the top of packageLine. When pkg is nil, still output the package path and elapsed time, but skip package-level metadata (cached, coverage, shuffleSeed) that require the Package object.

When converting benchmark output, Package() may return nil for
packages that only have benchmark events. packageLine then panics
trying to access pkg.cached on a nil pointer.

Add a nil check for pkg and handle the event without package-level
metadata (cached, coverage, shuffleSeed).

Fixes gotestyourself#413
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

panic when converting "go test -bench" output

1 participant