Skip to content

fix: prevent nil pointer panic when mission init fails#72

Merged
fank merged 1 commit intomainfrom
fix/nil-mission-panic
Feb 3, 2026
Merged

fix: prevent nil pointer panic when mission init fails#72
fank merged 1 commit intomainfrom
fix/nil-mission-panic

Conversation

@fank
Copy link
Member

@fank fank commented Feb 3, 2026

Summary

  • Add nil check in EndMission() to return error instead of panic when no mission was started
  • Add nil check in GetExportMetadata() to return empty metadata instead of panic
  • Add tests for both nil mission scenarios

Problem

When :INIT: fails (e.g., Arma addon passes any instead of an array), no mission is started. However, subsequent commands like :SAVE:MISSION: still execute. When EndMission() or GetExportMetadata() tried to access b.mission fields, it caused a nil pointer dereference panic:

["error", "panic in RVExtensionArgs: runtime error: invalid memory address or nil pointer dereference"]

Test plan

  • TestEndMissionWithoutStartMission - verifies error returned instead of panic
  • TestGetExportMetadataWithoutStartMission - verifies empty metadata returned instead of panic
  • All existing tests pass

When :INIT: fails (e.g., args passed as 'any' instead of array), no
mission is started but subsequent commands like :SAVE:MISSION: still
execute. EndMission() and GetExportMetadata() would then dereference
the nil b.mission pointer, causing a panic.

Add nil checks to return proper errors/empty values instead of crashing.
@github-actions
Copy link

github-actions bot commented Feb 3, 2026

Merging this branch will increase overall coverage

Impacted Packages Coverage Δ 🤖
github.com/OCAP2/extension/v5/internal/storage/memory 14.85% (+0.07%) 👍

Coverage by file

Changed files (no unit tests)

Changed File Coverage Δ Total Covered Missed 🤖
github.com/OCAP2/extension/v5/internal/storage/memory/memory.go 16.81% (+0.09%) 1410 (+40) 237 (+8) 1173 (+32) 👍

Please note that the "Total", "Covered", and "Missed" counts above refer to code statements instead of lines of code. The value in brackets refers to the test coverage of that file in the old version of the code.

Changed unit test files

  • github.com/OCAP2/extension/v5/internal/storage/memory/memory_test.go

@fank fank merged commit 87bcf9d into main Feb 3, 2026
3 checks passed
@fank fank deleted the fix/nil-mission-panic branch February 3, 2026 14:32
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.

1 participant