Skip to content

Fix panic when bare '@' is passed as a CLI argument#4013

Closed
RonGamzu wants to merge 2 commits into
microsoft:mainfrom
RonGamzu:fix/empty-response-file-panic
Closed

Fix panic when bare '@' is passed as a CLI argument#4013
RonGamzu wants to merge 2 commits into
microsoft:mainfrom
RonGamzu:fix/empty-response-file-panic

Conversation

@RonGamzu
Copy link
Copy Markdown

Fixes #3758

Problem

Running tsgo @ (an @ with no filename) causes a panic deep in the
vfs layer:

panic: vfs: path "" is not absolute

The @ prefix is the response-file convention: @file means "read
compiler arguments from this file." When no filename follows the @,
parseResponseFile receives an empty string and forwards it to
fs.ReadFile(""), which the vfs layer rejects with a panic rather than
a recoverable error.

Fix

Add an early guard in parseResponseFile that returns a
Cannot_read_file diagnostic when the filename is empty, consistent
with how every other unreadable-file case is handled in the same
function.

Testing

Added TestParseCommandLineEmptyResponseFile which exercises the @
argument directly and asserts a diagnostic is produced instead of a
panic.


This patch was authored with AI assistance (Claude Code). I have read,
understood, and am prepared to discuss the changes in review.

Passing '@' with no filename causes parseResponseFile to call
ReadFile with an empty string, which panics deep in the vfs layer.
Guard against it by checking for an empty fileName up front and
emitting a Cannot_read_file diagnostic instead.

Adds a regression test for this case.

Fixes microsoft#3758
Copilot AI review requested due to automatic review settings May 20, 2026 22:05
@RonGamzu
Copy link
Copy Markdown
Author

@microsoft-github-policy-service agree

Copy link
Copy Markdown
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

Fixes a CLI crash in tsgo when a bare @ is passed (response-file prefix with no filename) by converting the panic into a normal compiler diagnostic, and adds a regression test to ensure the behavior remains non-panicking.

Changes:

  • Add an early guard in parseResponseFile to handle an empty response-file name and emit Cannot_read_file instead of calling into the VFS with an invalid path.
  • Add a unit test that invokes ParseCommandLine with ["@"] and asserts an error diagnostic is produced.

Reviewed changes

Copilot reviewed 2 out of 2 changed files in this pull request and generated no comments.

File Description
internal/tsoptions/commandlineparser.go Guard against empty response-file names to prevent VFS panics and produce a diagnostic.
internal/tsoptions/commandlineparser_test.go Add regression test covering the bare @ CLI argument case.

@RyanCavanaugh
Copy link
Copy Markdown
Member

Did you read the comments on the issue? #3758 (comment)

Response files passed as relative paths (e.g. tsgo @BLAH) caused a
panic in the vfs layer ('path is not absolute') because ReadFile
requires absolute paths.

Fix by threading the host's current directory into commandLineParser
and resolving the response file name against it before reading,
using tspath.CombinePaths which correctly passes through paths that
are already absolute. The empty-string case (tsgo @) is still caught
up front to avoid silently reading the current directory.

Fixes microsoft#3758
@RonGamzu
Copy link
Copy Markdown
Author

@RyanCavanaugh I’ve read it over and made a few more edits and adjustments.

@RyanCavanaugh
Copy link
Copy Markdown
Member

Already addressed in #3859

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.

File argument of @ crashes CLI

3 participants