Files
bun.sh/test/regression/issue/1365.test.ts
robobun bcbb4fc35d fix(cli): show helpful error for unsupported file types instead of "File not found" (#26126)
## Summary

- When running `bun <file>` on a file with an unsupported type (e.g.,
`.css`, `.yaml`, `.toml`), Bun now shows a helpful error message instead
of the misleading "File not found"
- Tracks when a file is resolved but has a loader that can't be run
directly
- Shows the actual file path and file type in the error message

**Before:**
```
error: File not found "test.css"
```

**After:**
```
error: Cannot run "/path/to/test.css"
note: Bun cannot run css files directly
```

## Test plan

- [x] Added regression test in `test/regression/issue/1365.test.ts`
- [x] Test verifies unsupported files show "Cannot run" error
- [x] Test verifies nonexistent files still show "File not found"
- [x] Test fails with `USE_SYSTEM_BUN=1` and passes with debug build

Fixes #1365

🤖 Generated with [Claude Code](https://claude.com/claude-code)

---------

Co-authored-by: Claude Bot <claude-bot@bun.sh>
Co-authored-by: Claude Opus 4.5 <noreply@anthropic.com>
Co-authored-by: Jarred Sumner <jarred@jarredsumner.com>
2026-01-15 23:40:45 -08:00

48 lines
1.4 KiB
TypeScript

import { expect, test } from "bun:test";
import { bunEnv, bunExe, tempDir } from "harness";
test("running unsupported file types shows helpful error message instead of 'File not found'", async () => {
using dir = tempDir("issue-1365", {
"test.css": "body { color: red; }",
});
await using proc = Bun.spawn({
cmd: [bunExe(), "test.css"],
cwd: String(dir),
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stdout).toBe("");
// Should NOT say "File not found" since the file exists
expect(stderr).not.toContain("File not found");
// Should indicate the file cannot be run
expect(stderr).toContain("Cannot run");
expect(stderr).toContain("test.css");
// Should mention the file type
expect(stderr).toContain("css");
expect(exitCode).toBe(1);
});
test("actually missing files still show 'File not found'", async () => {
using dir = tempDir("issue-1365-missing", {});
await using proc = Bun.spawn({
cmd: [bunExe(), "nonexistent.css"],
cwd: String(dir),
env: bunEnv,
stderr: "pipe",
stdout: "pipe",
});
const [stdout, stderr, exitCode] = await Promise.all([proc.stdout.text(), proc.stderr.text(), proc.exited]);
expect(stdout).toBe("");
expect(stderr).toContain("File not found");
expect(stderr).toContain("nonexistent.css");
expect(exitCode).toBe(1);
});