Skip to content

Handle empty response file name in command line parser#3999

Closed
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix-3758-response-file-empty-name
Closed

Handle empty response file name in command line parser#3999
LeSingh1 wants to merge 1 commit into
microsoft:mainfrom
LeSingh1:fix-3758-response-file-empty-name

Conversation

@LeSingh1
Copy link
Copy Markdown

Fixes #3758.

Running tsgo with a bare @ argument crashes with a panic in the vfs layer:

panic: vfs: path "" is not absolute

The crash comes from parseStrings taking the suffix after @ (which is empty) and passing it to parseResponseFile, which then asks the vfs to read the empty path. RootLength in internal/vfs/internal panics on a non-absolute path, so the process exits before any diagnostic is reported.

This change short-circuits at the top of parseResponseFile when the file name is empty and reports the existing Cannot_read_file_0 diagnostic instead, which is what users would get for any other unreadable response file.

The change is four lines in internal/tsoptions/commandlineparser.go. I do not have a Go toolchain on this machine, so I have not run go test ./... or hereby test locally. Happy to add a baseline test once a maintainer confirms the approach, or if pointed at the right scenario harness.

When tsgo is invoked with a bare '@' argument, the command line parser
called parseResponseFile with an empty file name, which reached the vfs
layer and panicked with 'vfs: path "" is not absolute' from
RootLength.

Short-circuit in parseResponseFile when the file name is empty and
report the existing Cannot_read_file_0 diagnostic, matching the
behavior for a non-existent response file.

Fixes microsoft#3758
Copilot AI review requested due to automatic review settings May 20, 2026 04:15
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 the tsgo command-line parser when a response file argument is provided as a bare @ by short-circuiting response-file parsing and emitting Cannot_read_file_0 instead of reaching the VFS layer panic.

Changes:

  • Add an early check in parseResponseFile for an empty response file name and report Cannot_read_file_0 rather than calling into vfs.FS.ReadFile.
Comments suppressed due to low confidence (1)

internal/tsoptions/commandlineparser.go:169

  • Please add a regression test for the @-only argument so we verify this path reports Cannot_read_file_0 instead of panicking (there are existing command line parser tests in internal/tsoptions/commandlineparser_test.go). This repo’s guidelines expect at least one minimal test case for bug fixes.
	if fileName == "" {
		p.errors = append(p.errors, ast.NewCompilerDiagnostic(diagnostics.Cannot_read_file_0, fileName))
		return
	}

if fileName == "" {
p.errors = append(p.errors, ast.NewCompilerDiagnostic(diagnostics.Cannot_read_file_0, fileName))
return
}
@jakebailey
Copy link
Copy Markdown
Member

The right fix is in #3859; the issue is wider than empty strings

@jakebailey jakebailey closed this May 20, 2026
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