From 14397d3d627ee67f9fb2592a4a7580d9f1162b59 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:34:07 +0000 Subject: [PATCH 1/4] fix(NodeApp): end with "Internal server error" on mid-stream error --- packages/astro/src/core/app/node.ts | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/packages/astro/src/core/app/node.ts b/packages/astro/src/core/app/node.ts index ddfa70997c4a..db61157e319e 100644 --- a/packages/astro/src/core/app/node.ts +++ b/packages/astro/src/core/app/node.ts @@ -118,12 +118,12 @@ export class NodeApp extends App { destination.write(result.value); result = await reader.read(); } + destination.end(); // the error will be logged by the "on end" callback above } catch { - destination.write('Internal server error'); + destination.end('Internal server error'); } } - destination.end(); } } From 3a709588532003df41670617abd9f4b916f63aaf Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Wed, 31 Jan 2024 17:35:01 +0000 Subject: [PATCH 2/4] add changeset --- .changeset/clever-roses-sleep.md | 5 +++++ 1 file changed, 5 insertions(+) create mode 100644 .changeset/clever-roses-sleep.md diff --git a/.changeset/clever-roses-sleep.md b/.changeset/clever-roses-sleep.md new file mode 100644 index 000000000000..fd159eb3ba34 --- /dev/null +++ b/.changeset/clever-roses-sleep.md @@ -0,0 +1,5 @@ +--- +"astro": patch +--- + +Improves http behavior relating to errors encountered while streaming a response. From 50d1cd4953ea8fd110793e702e85d73442a7fc94 Mon Sep 17 00:00:00 2001 From: lilnasy <69170106+lilnasy@users.noreply.github.com> Date: Wed, 31 Jan 2024 18:09:25 +0000 Subject: [PATCH 3/4] add test --- .../integrations/node/test/errors.test.js | 19 +++++++++++++++++-- .../fixtures/errors/src/pages/generator.astro | 11 +++++++++++ 2 files changed, 28 insertions(+), 2 deletions(-) create mode 100644 packages/integrations/node/test/fixtures/errors/src/pages/generator.astro diff --git a/packages/integrations/node/test/errors.test.js b/packages/integrations/node/test/errors.test.js index 983187475799..3ad77a4cbfa5 100644 --- a/packages/integrations/node/test/errors.test.js +++ b/packages/integrations/node/test/errors.test.js @@ -1,4 +1,4 @@ -import * as assert from 'node:assert/strict'; +import assert from 'node:assert/strict'; import { describe, it, before, after } from 'node:test'; import nodejs from '../dist/index.js'; import { loadFixture } from './test-utils.js'; @@ -22,11 +22,26 @@ describe('Errors', () => { after(async () => { await devPreview.stop(); }); - it('when mode is standalone', async () => { + + it.skip('rejected promise in template', async () => { const res = await fixture.fetch('/in-stream'); const html = await res.text(); const $ = cheerio.load(html); assert.equal($('p').text().trim(), 'Internal server error'); }); + + it('generator that throws called in template', async () => { + /** @type {Response} */ + const res = await fixture.fetch('/generator'); + const reader = res.body.getReader(); + const decoder = new TextDecoder(); + const expect = async ({ done, value }) => { + const result = await reader.read(); + assert.equal(result.done, done); + if (!done) assert.equal(decoder.decode(result.value), value); + } + await expect({ done: false, value: "