Skip to content

Remove stack trace from user errors#1320

Merged
victorlin merged 1 commit intomasterfrom
victorlin/trim-logs
Feb 27, 2026
Merged

Remove stack trace from user errors#1320
victorlin merged 1 commit intomasterfrom
victorlin/trim-logs

Conversation

@victorlin
Copy link
Member

@victorlin victorlin commented Feb 26, 2026

Express' default error handler always logs a full stack trace to stderr, even for expected client-side errors like 404s. This adds significant noise (10+ lines per error) to production server logs.

Slack thread for context.

Checklist

  • Tested locally with curl -I -X POST -H 'accept: text/html' http://localhost:5000/

    Before:

     [verbose]       Sending NotFoundError: Not Found error as HTML with Express' default error handler
     NotFoundError: Not Found
         at file:///…/nextstrain.org/src/routing/errors.js:25:36
         at Layer.handle [as handle_request] (/…/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
         at trim_prefix (/…/nextstrain.org/node_modules/express/lib/router/index.js:317:13)
         at /…/nextstrain.org/node_modules/express/lib/router/index.js:284:7
         at router.process_params (/…/nextstrain.org/node_modules/express/lib/router/index.js:335:12)
         at next (/…/nextstrain.org/node_modules/express/lib/router/index.js:275:10)
         at file:///…/nextstrain.org/src/routing/canary.js:21:12
         at Layer.handle [as handle_request] (/…/nextstrain.org/node_modules/express/lib/router/layer.js:95:5)
         at trim_prefix (/…/nextstrain.org/node_modules/express/lib/router/index.js:317:13)
         at /…/nextstrain.org/node_modules/express/lib/router/index.js:284:7
    

    After:

     [verbose]       Sending NotFoundError: Not Found error as plain text
     NotFoundError: Not Found
    
  • Checks pass

  • Check if changes affect the resource index JSON revision

@victorlin victorlin self-assigned this Feb 26, 2026
Copy link
Member

@jameshadfield jameshadfield left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks!

Express' default error handler (finalhandler) always logs a full stack
trace to stderr, even for expected client-side errors like 404s. This
adds significant noise (10+ lines per error) to production server logs.
@victorlin victorlin changed the title Send user errors as plain text Remove stack trace from user errors Feb 27, 2026
@victorlin victorlin merged commit 73f1550 into master Feb 27, 2026
10 checks passed
@victorlin victorlin deleted the victorlin/trim-logs branch February 27, 2026 01:26
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.

2 participants