mirror of
https://github.com/oven-sh/bun
synced 2026-02-02 15:08:46 +00:00
## 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>
48 lines
1.4 KiB
TypeScript
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);
|
|
});
|