Skip to content

Conversation

Copy link
Contributor

Copilot AI commented Dec 24, 2025

Task files with only frontmatter and whitespace/newlines caused parser failure with unexpected token "\n".

Changes

  • taskparser.ParseTask(): Return empty Task for whitespace-only content instead of attempting to parse
  • Error messages: Include file path in parse errors for faster debugging
  • Tests: Cover empty content, newlines, and whitespace-only edge cases

Example

Task file that previously failed:

---
task_name: my-task
---

Now parses successfully and returns an empty task.

Original prompt

failed to generate coding context: task not found: failed to find task: failed to walk directory /tmp/0c0a4662f6811735b5c6ca39e9ebeecdb11798260e5663b3b0309ea4687dc3ab/.agents/tasks: failed to parse task content: 1:1: unexpected token \"\\n\""


💬 We'd love your input! Share your thoughts on Copilot coding agent in our 2 minute survey.

- Handle empty/whitespace-only task content gracefully in ParseTask
- Add file path to "failed to parse task content" error message
- Add unit tests for newline-only and whitespace-only inputs
- Add integration tests for tasks with empty content

Co-authored-by: alexec <1142830+alexec@users.noreply.github.com>
Copilot AI changed the title [WIP] Fix task parsing error in agent directory Fix parser failure on empty task content Dec 24, 2025
Copilot AI requested a review from alexec December 24, 2025 01:20
@alexec alexec marked this pull request as ready for review December 24, 2025 01:21
Copilot AI review requested due to automatic review settings December 24, 2025 01:21
@alexec alexec enabled auto-merge (squash) December 24, 2025 01:21
@alexec alexec merged commit 95cb263 into main Dec 24, 2025
5 checks passed
@alexec alexec deleted the copilot/fix-task-parsing-error branch December 24, 2025 01:22
Copy link
Contributor

Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR fixes a parser failure that occurred when task files contained only frontmatter followed by empty or whitespace-only content. The error unexpected token "\n" is now prevented by adding an early check for whitespace-only content before attempting to parse.

Key Changes:

  • Added whitespace-only content check in ParseTask() to return empty task instead of failing
  • Enhanced error messages to include file paths for easier debugging
  • Added comprehensive test coverage for empty content edge cases

Reviewed changes

Copilot reviewed 4 out of 4 changed files in this pull request and generated 1 comment.

File Description
pkg/codingcontext/taskparser/taskparser.go Added early return for whitespace-only content to prevent parser failure
pkg/codingcontext/taskparser/taskparser_test.go Added table-driven test cases covering empty string, newlines, and whitespace-only scenarios
pkg/codingcontext/context.go Enhanced error message to include file path when task parsing fails
integration_test.go Added end-to-end test verifying empty task files are handled gracefully

Comment on lines +1699 to +1700
if output == "" {
t.Errorf("expected some output, got empty string")
Copy link

Copilot AI Dec 24, 2025

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The test validation is too weak. It only checks that output is non-empty, but doesn't verify that the task was actually processed correctly. Consider adding a more specific assertion, such as checking for expected content in the output or verifying that the program completed without errors. For consistency with other integration tests in this file, you could check for specific markers or content that should be present in the output.

Copilot uses AI. Check for mistakes.
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.

2 participants