Skip to content

fix: stop spurious mount warnings and reject unusable validation config - #10

Merged
Michael McQuade (giraffesyo) merged 1 commit into
masterfrom
fix/logging-and-validation-hardening
Oct 1, 2026
Merged

Michael McQuade (giraffesyo) merged 1 commit into
masterfrom
fix/logging-and-validation-hardening

Conversation

@giraffesyo

Copy link
Copy Markdown
Member

Summary

Fixes the mount-time log noise and tightens a few places where a route file could be misconfigured without anyone noticing.

Logging

  • The "handler is not async" warning was checked against every handler on a route, including the query and body validators that fsrouter adds itself, which are not async. Any route with validation printed the warning even when its own handler was async. Only the handlers exported by the route file are checked now, and the warning goes to console.warn instead of console.error.
  • Nothing is printed while mounting when logMounts is false. A test asserts this.
  • Mounting a single file printed Mounting route: with an empty path, it now prints /.
  • defaultErrorHandler logged "shown in development" in production too. The message no longer mentions the environment.

Validation

  • A key other than body or query under validation.<METHOD> (e.g. Body) was ignored, so the route was mounted "with validation" but nothing was validated. This is now an error at startup, as is a schema that is not an object.
  • Validation for a method that the file does not export a handler for is an error at startup, the same as roles.

Routing

  • Files in a folder prefixed with _ are skipped, like files prefixed with _ already were. Before, a helper such as _lib/helper.ts that exports a function named get was mounted as a route.
  • Route paths are built with forward slashes whatever the path separator of the platform is. This is not covered by a test, CI only runs on Linux.

Errors

  • A UserFacingError whose status code is not an integer from 400 to 599 is answered with a 500, instead of a success status or a failed response.

Upgrade notes

  • A route under a _ prefixed folder is no longer mounted.
  • A route file with a validation key other than body or query, or with validation for a method that it does not export, stops the router from starting.

Testing

  • pnpm typecheck, pnpm test (41 tests, 16 new) and pnpm build pass. 10 of the new tests fail against the previous source.
  • Mounted the routes of parallelworks/core packages/api with 0.2.2 and with this branch: the same 12 routes with the same handlers, and identical responses to 12 requests in production and development mode.

The not-async warning was raised for the validators that fsrouter adds itself, so every route with validation printed it. Only the handlers that a route file exports are checked now.

Validation keys other than body and query, schemas that are not objects, and validation for a method without a handler now stop the router from starting. Files in a folder prefixed with _ are skipped. A UserFacingError status code outside of 400-599 is answered with a 500.
@giraffesyo
Michael McQuade (giraffesyo) merged commit 1e48e51 into master Oct 1, 2026
8 checks passed
@giraffesyo
Michael McQuade (giraffesyo) deleted the fix/logging-and-validation-hardening branch October 1, 2026 23:47
@github-actions github-actions Bot mentioned this pull request Oct 1, 2026
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.

1 participant