Skip to content

fix(compare): handle missing results directory - #497

Merged
Tony133 merged 1 commit into
fastify:mainfrom
RaphaelFakhri:fix/compare-missing-results-dir
Nov 14, 2026
Merged

Tony133 merged 1 commit into
fastify:mainfrom
RaphaelFakhri:fix/compare-missing-results-dir

Conversation

@RaphaelFakhri

Copy link
Copy Markdown
Contributor

benchmark compare crashes with ENOENT: no such file or directory, scandir '<cwd>/results' when the results directory for the selected scenario does not exist. This happens on a fresh clone before any benchmark run, and with -s post after running only the GET scenario. The command already has a friendly message for this case ("Benchmark to gather some results to compare."), but readdirSync throws before the check runs.

This change makes getAvailableResults() return an empty list when the results directory is missing, so the existing message is shown and the command exits with code 0.

Fixes #496

How to reproduce

npm i --ignore-scripts
rm -rf results
node ./benchmark compare -t           # before: ENOENT stack trace, exit 1
node ./benchmark compare -t -s post   # before: ENOENT stack trace, exit 1

After the change, both commands print Benchmark to gather some results to compare. and exit 0. Comparing existing results is unchanged.

Checklist

  • run npm run test && npm run benchmark --if-present
  • tests and/or benchmarks are included (the repository has no test suite; npm test runs standard only. Verified manually with the commands above.)
  • documentation is changed or added (not needed)
  • commit message and code follows the Developer's Certification of Origin
    and the Code of conduct

@SameRainbows

Copy link
Copy Markdown

Tested locally on Node 24 (Windows).

Running node ./benchmark-compare.js -t without an existing results/ folder previously crashed immediately with ENOENT: no such file or directory, scandir .../results. Adding if (!existsSync(resultsPath)) return [] allows !getAvailableResults().length to catch the empty state as intended and prints Benchmark to gather some results to compare. before exiting cleanly with code 0.

Works identically when specifying -s post where other scenario subdirectories have not yet been created. Lint check via npm test is clean.

@Tony133
Tony133 merged commit fcf8e8a into fastify:main Nov 14, 2026
8 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

benchmark compare crashes with ENOENT when no results exist

4 participants