Skip to content

fix: LavaFormatLog must always return error when called#2167

Merged
nimrod-teich merged 1 commit into
mainfrom
fix/parser-nil-pointer-panic
Dec 31, 2025
Merged

fix: LavaFormatLog must always return error when called#2167
nimrod-teich merged 1 commit into
mainfrom
fix/parser-nil-pointer-panic

Conversation

@nimrod-teich

@nimrod-teich nimrod-teich commented Dec 31, 2025

Copy link
Copy Markdown
Contributor

The early return optimization in #2155 broke the contract that LavaFormat*
functions always return an error. When log level was disabled and no original
error was passed, it returned nil instead of an error.

This caused issues like:
return nil, utils.LavaFormatTrace("error message")
to return (nil, nil) instead of (nil, error), leading to nil pointer panics
in code that relied on the error return.

Changes:

  • utils/lavalog.go: Return fmt.Errorf based on description when log level
  • disabled and no original error
  • protocol/parser/parser.go: Add defensive nil checks as safety net

Description

Closes: #XXXX


Author Checklist

All items are required. Please add a note to the item if the item is not applicable and
please add links to any relevant follow up issues.

I have...

  • read the contribution guide
  • included the correct type prefix in the PR title, you can find examples of the prefixes below:
  • confirmed ! in the type prefix if API or client breaking change
  • targeted the main branch
  • provided a link to the relevant issue or specification
  • reviewed "Files changed" and left comments if necessary
  • included the necessary unit and integration tests
  • updated the relevant documentation or specification, including comments for documenting Go code
  • confirmed all CI checks have passed

Reviewers Checklist

All items are required. Please add a note if the item is not applicable and please add
your handle next to the items reviewed if you only reviewed selected items.

I have...

  • confirmed the correct type prefix in the PR title
  • confirmed all author checklist items have been addressed
  • reviewed state machine logic, API design and naming, documentation is accurate, tests and test coverage

The early return optimization in #2155 broke the contract that LavaFormat*
functions always return an error. When log level was disabled and no original
error was passed, it returned nil instead of an error.

This caused issues like:
  return nil, utils.LavaFormatTrace("error message")
to return (nil, nil) instead of (nil, error), leading to nil pointer panics
in code that relied on the error return.

Changes:
- utils/lavalog.go: Return fmt.Errorf based on description when log level
  disabled and no original error
- protocol/parser/parser.go: Add defensive nil checks as safety net
@nimrod-teich nimrod-teich force-pushed the fix/parser-nil-pointer-panic branch from a7ad6b4 to 15d53a6 Compare December 31, 2025 12:59
@nimrod-teich nimrod-teich changed the title fix: prevent nil pointer panic in generic parser flow fix: LavaFormatLog must always return error when called Dec 31, 2025
@nimrod-teich nimrod-teich merged commit 9184964 into main Dec 31, 2025
30 checks passed
@nimrod-teich nimrod-teich deleted the fix/parser-nil-pointer-panic branch December 31, 2025 13:07
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants