runtime-tools icon indicating copy to clipboard operation
runtime-tools copied to clipboard

Fix nil ptr panic when adding env variables to uninitialized Generator

Open andreaskaris opened this issue 2 months ago • 0 comments

When calling AddProcessEnv on a Generator instance that was created using zero-value initialization (Generator{}) rather than through New(), the envMap field would be nil. This caused a panic when attempting to write to the map in the addEnv helper function.

This commit adds a nil check before writing to the envMap in addEnv. If the map is uninitialized, it creates a new empty map before proceeding with the map insertion operation.

A new test case has been added to TestEnvCaching that validates this scenario by creating a Generator using zero-value initialization and verifying that AddProcessEnv works correctly without panicking.

Fixes #790

andreaskaris avatar Oct 03 '25 17:10 andreaskaris