fix: error throwing in reply#6299
Merged
Uzlopak merged 5 commits intoSep 26, 2025
Merged
Conversation
Signed-off-by: Juan L. <[email protected]> Signed-off-by: Juan Letamendia <[email protected]>
Eomm
reviewed
Aug 24, 2025
Eomm
left a comment
Member
There was a problem hiding this comment.
Checking the fastify/error docs, the fix seems legit!
jsumners
reviewed
Aug 25, 2025
gurgunday
requested changes
Aug 25, 2025
gurgunday
left a comment
Member
There was a problem hiding this comment.
We are currently using a combination of both
Using new is a little faster with fastify-error as it internally checks if 'new' was used:
Node.js v22.18.0
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'new FST_ERR_HELLO_WORLD()' │ '3060.9 ± 0.50%' │ '3000.0 ± 41.00' │ '331807 ± 0.06%' │ '333333 ± 4619' │ 32671 │
│ 1 │ 'FST_ERR_HELLO_WORLD()' │ '3352.6 ± 0.41%' │ '3292.0 ± 42.00' │ '302058 ± 0.07%' │ '303767 ± 3827' │ 29828 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'new FST_ERR_HELLO_WORLD()' │ '3203.0 ± 0.32%' │ '3083.0 ± 42.00' │ '321557 ± 0.02%' │ '324359 ± 4480' │ 312208 │
│ 1 │ 'FST_ERR_HELLO_WORLD()' │ '3349.8 ± 0.84%' │ '3292.0 ± 42.00' │ '302262 ± 0.01%' │ '303767 ± 3926' │ 298526 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'new FST_ERR_HELLO_WORLD()' │ '3051.4 ± 0.12%' │ '3041.0 ± 42.00' │ '329605 ± 0.01%' │ '328839 ± 4494' │ 327722 │
│ 1 │ 'FST_ERR_HELLO_WORLD()' │ '3329.1 ± 0.13%' │ '3292.0 ± 42.00' │ '302065 ± 0.01%' │ '303767 ± 3926' │ 300383 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'new FST_ERR_HELLO_WORLD()' │ '3106.9 ± 0.19%' │ '3041.0 ± 41.00' │ '327357 ± 0.02%' │ '328839 ± 4494' │ 321861 │
│ 1 │ 'FST_ERR_HELLO_WORLD()' │ '3350.2 ± 0.19%' │ '3291.0 ± 41.00' │ '302658 ± 0.02%' │ '303859 ± 3833' │ 298491 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'FST_ERR_HELLO_WORLD()' │ '3359.3 ± 0.15%' │ '3292.0 ± 42.00' │ '301922 ± 0.02%' │ '303767 ± 3926' │ 297679 │
│ 1 │ 'new FST_ERR_HELLO_WORLD()' │ '3104.5 ± 0.64%' │ '3041.0 ± 41.00' │ '327729 ± 0.02%' │ '328839 ± 4494' │ 322115 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘
node test.mjs
Running benchmark...
┌─────────┬─────────────────────────────┬──────────────────┬──────────────────┬────────────────────────┬────────────────────────┬─────────┐
│ (index) │ Task name │ Latency avg (ns) │ Latency med (ns) │ Throughput avg (ops/s) │ Throughput med (ops/s) │ Samples │
├─────────┼─────────────────────────────┼──────────────────┼──────────────────┼────────────────────────┼────────────────────────┼─────────┤
│ 0 │ 'new FST_ERR_HELLO_WORLD()' │ '3062.3 ± 0.14%' │ '3000.0 ± 42.00' │ '329698 ± 0.01%' │ '333333 ± 4733' │ 326554 │
│ 1 │ 'FST_ERR_HELLO_WORLD()' │ '3325.5 ± 0.15%' │ '3292.0 ± 42.00' │ '302632 ± 0.01%' │ '303767 ± 3926' │ 300705 │
└─────────┴─────────────────────────────┴──────────────────┴──────────────────┴────────────────────────┴────────────────────────┴─────────┘Benchmark
import { Bench } from 'tinybench';
import createError from '@fastify/error';
// --- Setup ---
// First, we create a custom error constructor using the factory.
// This is typically done once when your application starts.
const FST_ERR_HELLO_WORLD = createError(
'FST_ERR_HELLO_WORLD',
'Hello, %s!',
500
);
const bench = new Bench({ time: 1000 });
let err = null;
// --- Benchmarking Scenarios ---
bench
// Scenario 1: Using 'new' with the created error constructor.
.add('new FST_ERR_HELLO_WORLD()', () => {
err = new FST_ERR_HELLO_WORLD('world');
})
// Scenario 2: Calling the constructor directly as a function.
.add('FST_ERR_HELLO_WORLD()', () => {
err = FST_ERR_HELLO_WORLD('world');
})
async function runBenchmark() {
console.log('Running benchmark...');
await bench.run();
console.table(bench.table());
}
runBenchmark();Please fix the test to use node:test
Member
|
I think we don't need the test here |
gurgunday
approved these changes
Sep 26, 2025
jean-michelet
pushed a commit
to jean-michelet/fastify
that referenced
this pull request
Sep 27, 2025
… error-parameter for setErrorHandler and errorHandler to unknown, but configurable via generic TError (fastify#6308) * types: loosen setErrorHandler and errorHandler types * set TError to unknown add generic to errorHandler * fix * remove obsolte type tst * add unit test, fix potential issue --------- Co-authored-by: Jean <[email protected]> build(deps-dev): remove @fastify/pre-commit (fastify#6319) `@fastify/pre-commit` isn't configured or used in this repo as there is no `pre-commit` object in package.json. It won't run regardless as scripts are disabled. Signed-off-by: Frazer Smith <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> ci: improve citgm workflows (fastify#6334) * ci: improve citgm workflows * fix remark docs: explain stream error handling (fastify#5746) * docs: explain stream error handling * Update docs/Reference/Server.md Co-authored-by: Matteo Collina <[email protected]> Signed-off-by: James Sumners <[email protected]> * Apply suggestions from code review Co-authored-by: Frazer Smith <[email protected]> Signed-off-by: Denys Otrishko <[email protected]> * docs: explain stream error handling * fix test --------- Signed-off-by: James Sumners <[email protected]> Signed-off-by: Denys Otrishko <[email protected]> Signed-off-by: Aras Abbasi <[email protected]> Co-authored-by: James Sumners <[email protected]> Co-authored-by: Matteo Collina <[email protected]> Co-authored-by: Frazer Smith <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> fix: error throwing in reply (fastify#6299) * fix: instantiate readable stream error * Create reply-web-stream-locked.test.js Signed-off-by: Juan L. <[email protected]> Signed-off-by: Juan Letamendia <[email protected]> * fix test --------- Signed-off-by: Juan L. <[email protected]> Signed-off-by: Juan Letamendia <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> docs: create 2 frst chapters of the tutorial docs: nit docs: create a fastify server docs: create basic routes docs: improve chapter 4 refactor: improve readability and quote examples docs: decoration chapter public part docs: decoration chapter public part fix: typo fix: typo fix: markdown lint docs: document internals docs: validatio nand serialization docs: move section mapping reminder with routes declarations docs: add hooks chapter docs: remove internals involved sections docs: add error handling chapter fix: copilot suggestions
jean-michelet
pushed a commit
to jean-michelet/fastify
that referenced
this pull request
Sep 27, 2025
… error-parameter for setErrorHandler and errorHandler to unknown, but configurable via generic TError (fastify#6308) * types: loosen setErrorHandler and errorHandler types * set TError to unknown add generic to errorHandler * fix * remove obsolte type tst * add unit test, fix potential issue --------- Co-authored-by: Jean <[email protected]> build(deps-dev): remove @fastify/pre-commit (fastify#6319) `@fastify/pre-commit` isn't configured or used in this repo as there is no `pre-commit` object in package.json. It won't run regardless as scripts are disabled. Signed-off-by: Frazer Smith <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> ci: improve citgm workflows (fastify#6334) * ci: improve citgm workflows * fix remark docs: explain stream error handling (fastify#5746) * docs: explain stream error handling * Update docs/Reference/Server.md Co-authored-by: Matteo Collina <[email protected]> Signed-off-by: James Sumners <[email protected]> * Apply suggestions from code review Co-authored-by: Frazer Smith <[email protected]> Signed-off-by: Denys Otrishko <[email protected]> * docs: explain stream error handling * fix test --------- Signed-off-by: James Sumners <[email protected]> Signed-off-by: Denys Otrishko <[email protected]> Signed-off-by: Aras Abbasi <[email protected]> Co-authored-by: James Sumners <[email protected]> Co-authored-by: Matteo Collina <[email protected]> Co-authored-by: Frazer Smith <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> fix: error throwing in reply (fastify#6299) * fix: instantiate readable stream error * Create reply-web-stream-locked.test.js Signed-off-by: Juan L. <[email protected]> Signed-off-by: Juan Letamendia <[email protected]> * fix test --------- Signed-off-by: Juan L. <[email protected]> Signed-off-by: Juan Letamendia <[email protected]> Co-authored-by: Aras Abbasi <[email protected]> docs: create 2 frst chapters of the tutorial docs: nit docs: create a fastify server docs: create basic routes docs: improve chapter 4 refactor: improve readability and quote examples docs: decoration chapter public part docs: decoration chapter public part fix: typo fix: typo fix: markdown lint docs: document internals docs: validatio nand serialization docs: move section mapping reminder with routes declarations docs: add hooks chapter docs: remove internals involved sections docs: add error handling chapter fix: copilot suggestions
|
This pull request has been automatically locked since there has not been any recent activity after it was closed. Please open a new issue for related bugs. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to subscribe to this conversation on GitHub.
Already have an account?
Sign in.
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Description
Instantiate
FST_ERR_REP_READABLE_STREAM_LOCKEDwithnewinsendWebStream, matching other thrown Fastify errors.Checklist
npm run test && npm run benchmark --if-presenttest/reply-web-stream-locked.test.js)