Skip to content

Application errors are not logging, only generating Boom "Internal Server Error" logs #4475

Open

Description

@geuis

Runtime

node

Runtime version

21.1

Module version

huh?

Used with

hapi 21.3.2

Any other relevant information

No response

How can we help?

Ran into an issue where errors generated by application code are having their errors suppressed run in debug mode locally.

I have a route that is generating an error. When running locally, I'm just getting Boom internal server errors and not getting the actual error log messages.

I have the route wrapped in a try/catch and I can console.error the full logs in the catch, but I feel like there should be a global routes setting somewhere like debug that will just dump all errors like this to the console without needing special handling each time.

Note that failAction below does not get triggered either.

I've read up on debug https://hapi.dev/api/?v=21.3.2#-serveroptionsdebug though maybe I'm missing something?

My current server config:

  const server = Hapi.server({
    port: 2000,
    host: '0.0.0.0',
    routes: {
      validate: {
        failAction: async (req, h, err) => {
          console.error(err);
          throw err;
        }
      }
    },
    debug: {
      log: ['*'],
      request: ['*']
    },
  });

Activity

  1. added
    supportQuestions, discussions, and general support
    on Nov 18, 2023
  2. geuis commented on Dec 10, 2023

    @geuis
    Author

    I'm adding some follow up to this since its been a few weeks without any response.

    I've been through the documentation on logging:

    Here's a sample route for some Stripe webhooks I'm working on:

      server.route({
        path: '/api/v1/webhooks',
        method: 'post',
        options: {
          auth: false,
          payload: {
            parse: false
          }
        },
        handler: async (req, h) => {
          let sig;
          let stripeEvent;
    
          try {
            sig = req.headers['stripe-signature'];
            stripeEvent = stripeClient.webhooks.constructEvent(req.payload.toString(), sig, process.env.STRIPE_WEBHOOK_ENDPOINT_SECRET);
          } catch (err) {
            // this logs to the console.
            console.log('webhook signature verification failed:', err.message);
            return h.response().code(400);
          }
    
          try {
            const { type: eventType } = stripeEvent;
    
            switch (eventType) {
              // this contains some code that intentionally causes an error when I run "stripe trigger customer.subscription.deleted"
    
                break;
              }
    
              default:
                console.log(`Unhandled webhook: ${eventType}`);
                break;
            }
    
            return h.response().code(200);
          } catch (err) {
            // not seen
            process.stdout.write(err);
    
            // not seen
            console.error(`Webhook eventType: ${eventType}`, err);
            
            // not seen
            server.log('error', `Webhook eventType: ${eventType}`);
    
            // not seen 
            req.log('error', `Webhook eventType: ${eventType}`);
    
            throw err;
          }
    

    All I get in the terminal is

    Debug: handler, error 
        {"code":"ERR_UNKNOWN_ENCODING","isBoom":true,"isServer":true,"data":null,"output":{"statusCode":500,"payload":{"statusCode":500,"error":"Internal Server Error","message":"An internal server error occurred"},"headers":{}},"isDeveloperError":true}
    2023-12-09 23:31:40  <--  [500] POST http://localhost:2000/api/v1/webhooks [evt_1OLhUFCKVl5kfDhd9LsStTaA]
    

    I'm probably missing something, but I've been through the docs and I think I have this configured correctly. However, the callstack for the errors are being hidden.

  3. kanongil commented on Dec 11, 2023

    @kanongil
    Contributor

    You are probably not seeing the stack trace since you are using a not yet supported node runtime (v21.x), where they can go missing due to a change described in hapijs/boom#302.

    For the current version of hapi I would advise you to stay on node v18 for the time being.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    supportQuestions, discussions, and general support

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions