medusajs / medusa

The world's most flexible commerce platform.
https://medusajs.com
MIT License
25.8k stars 2.58k forks source link

Bundled logger doesn't print error when NODE_ENV is set #9862

Open turacma opened 1 week ago

turacma commented 1 week ago

Bug report

Describe the bug

When NODE_ENV is set to production/staging, the default logger switches to using JSON formatting, but when passed a error as part of a catch statement doesn't actually print the error details.

System information

Medusa version (including plugins): Node.js version: 20.15.1 Database: Postgres Operating system: Mac OS Browser (if relevant): N/A

Steps to reproduce the behavior

  1. Create a new medusa installation
  2. Configure as normal
  3. Break the configuration such that it won't start, note that the actual error is logged
  4. run export NODE_ENV=staging or export NODE_ENV=production then start again, note that error is not printed, only stack trace and the message.

Expected behavior

Ideally I would be able to provide my own logger implementation to use, but failing that, the bundled logger should at least print out the error details when providered.

Screenshots

N/A

Code snippets

N/A

Additional context

Not sure if related to my configuration or a general problem, but also noticing that when NODE_ENV=staging|production server fails to start up with the error

Error starting server Error: Could not find index.html in the admin build directory. Make sure to run 'medusa build' before starting the server.
    at serve (/Users/turacma/Workspace/ship/node_modules/@medusajs/admin-bundler/dist/index.js:1344:11)
    at serveProductionBuild (/Users/turacma/Workspace/ship/node_modules/@medusajs/medusa/src/loaders/admin.ts:75:28)
    at async loadEntrypoints (/Users/turacma/Workspace/ship/node_modules/@medusajs/medusa/src/loaders/index.ts:108:3)
    at async exports.default (/Users/turacma/Workspace/ship/node_modules/@medusajs/medusa/src/loaders/index.ts:164:31)
    at async internalStart (/Users/turacma/Workspace/ship/node_modules/@medusajs/medusa/src/commands/start.ts:120:50)
    at async start (/Users/turacma/Workspace/ship/node_modules/@medusajs/medusa/src/commands/start.ts:221:5)
turacma commented 1 week ago

Forking the additional context to a new issue report

thetutlage commented 4 days ago

Hello @turacma

I just gave it a try by pointing a non-existing module and everything looks fine to me as per the shared screenshot. Are you seeing things differently?

CleanShot 2024-11-04 at 12 20 23@2x

thetutlage commented 4 days ago

Also, its worth mentioning. If you are running the production build (ie, the JavaScript output). You must cd into the .medusa/server directory and run it from there.

turacma commented 4 days ago

Also, its worth mentioning. If you are running the production build (ie, the JavaScript output). You must cd into the .medusa/server directory and run it from there.

Yep, this was noted in my other bug report. As noted there, FWIW, this didn't seem to be necessary with the preview build I was using previously.

Here's an example of breaking something in the middleware:

-zsh -zsh

Might be be because it's a nested exception?

thetutlage commented 3 days ago

Might be be because it's a nested exception

Okay, yes. The cause property is not entertained when the JSON output is used. Sure, this is something we will look into and fix.

Thanks for reporting the issue :)

thetutlage commented 2 days ago

Fixed by: https://github.com/medusajs/medusa/pull/9944