Fix JSON unmarshaling error in task environment handling #3278
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.
Resolves issue #3190 where manual task execution fails with "Cannot write new event to database" error containing "unexpected end of JSON input".
Problem
When manually executing tasks through the UI or API, users encountered a 500 error with the message:
"Request failed with status code 500"
level=error msg="unexpected end of JSON input" error="Cannot write new event to database"
Scheduled tasks worked correctly, but manual execution consistently failed.
Root Cause
The issue was in the
populateTaskEnvironment()
method inservices/tasks/TaskRunner.go
. The code attempted to unmarshalEnvironment.JSON
without checking if the field was empty, causing a JSON parsing error when the environment template had no JSON content.Solution
Added a validation check to only attempt JSON unmarshaling when the field contains data:
This maintains the original functionality when valid JSON is present while preventing the parsing error for empty environment configurations.
Testing
💡 You can make Copilot smarter by setting up custom instructions, customizing its development environment and configuring Model Context Protocol (MCP) servers. Learn more Copilot coding agent tips in the docs.