aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--src/bun.js/bindings/exports.zig6
-rw-r--r--test/js/bun/http/error-response.js8
-rw-r--r--test/js/bun/http/serve.test.ts15
3 files changed, 26 insertions, 3 deletions
diff --git a/src/bun.js/bindings/exports.zig b/src/bun.js/bindings/exports.zig
index db6de2ef3..e9e9d3a8d 100644
--- a/src/bun.js/bindings/exports.zig
+++ b/src/bun.js/bindings/exports.zig
@@ -460,7 +460,7 @@ pub const ZigStackTrace = extern struct {
var source_line_len = source_lines_iter.getLength();
if (source_line_len > 0) {
- var source_lines = try allocator.alloc(Api.SourceLine, @intCast(usize, @max(source_lines_iter.i, 0)));
+ var source_lines = try allocator.alloc(Api.SourceLine, @intCast(usize, @max(source_lines_iter.i + 1, 0)));
var source_line_buf = try allocator.alloc(u8, source_line_len);
source_lines_iter = this.sourceLineIterator();
var remain_buf = source_line_buf[0..];
@@ -468,7 +468,7 @@ pub const ZigStackTrace = extern struct {
while (source_lines_iter.next()) |source| {
const text = source.text.slice();
defer source.text.deinit();
- defer bun.copy(
+ bun.copy(
u8,
remain_buf,
text,
@@ -515,7 +515,7 @@ pub const ZigStackTrace = extern struct {
pub fn getLength(this: *SourceLineIterator) usize {
var count: usize = 0;
- for (this.trace.source_lines_ptr[0..@intCast(usize, this.i)]) |*line| {
+ for (this.trace.source_lines_ptr[0..@intCast(usize, this.i + 1)]) |*line| {
count += line.length();
}
diff --git a/test/js/bun/http/error-response.js b/test/js/bun/http/error-response.js
new file mode 100644
index 000000000..3284c146b
--- /dev/null
+++ b/test/js/bun/http/error-response.js
@@ -0,0 +1,8 @@
+const s = Bun.serve({
+ fetch(req, res) {
+ s.stop(true);
+ throw new Error("1");
+ },
+ port: 0,
+});
+fetch(`http://${s.hostname}:${s.port}`).then(res => console.log(res.status));
diff --git a/test/js/bun/http/serve.test.ts b/test/js/bun/http/serve.test.ts
index 7182ba68d..bba35c085 100644
--- a/test/js/bun/http/serve.test.ts
+++ b/test/js/bun/http/serve.test.ts
@@ -2,8 +2,10 @@ import { file, gc, Serve, serve, Server } from "bun";
import { afterEach, describe, it, expect, afterAll } from "bun:test";
import { readFileSync, writeFileSync } from "fs";
import { resolve } from "path";
+import { bunExe, bunEnv } from "harness";
import { renderToReadableStream } from "react-dom/server";
import app_jsx from "./app.jsx";
+import { spawn } from "child_process";
type Handler = (req: Request) => Response;
afterEach(() => gc(true));
@@ -980,6 +982,19 @@ describe("should support Content-Range with Bun.file()", () => {
}
});
+it("formats error responses correctly", async () => {
+ const c = spawn(bunExe(), ["./error-response.js"], { cwd: import.meta.dir, env: bunEnv });
+
+ var output = "";
+ c.stderr.on("data", chunk => {
+ output += chunk.toString();
+ });
+ c.stderr.on("end", () => {
+ expect(output).toContain('throw new Error("1");');
+ c.kill();
+ });
+});
+
it("request body and signal life cycle", async () => {
{
const headers = {