Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Customizations with import errors can fail with wrong error notice #289

Open
afischer opened this issue Aug 31, 2021 · 0 comments
Open

Customizations with import errors can fail with wrong error notice #289

afischer opened this issue Aug 31, 2021 · 0 comments
Labels
bug Something isn't working

Comments

@afischer
Copy link
Member

Context

When running an instance of Library with items in the customizations directory, these customizations may import their own modules using require. If an error occurs in any of the requires at the top of a customization file, the error thrown will have the code MODULE_NOT_FOUND, making our check for that error code in our requireWithFallback logic incorrectly assume the custom file does not exist:

library/server/utils.js

Lines 57 to 62 in d85eb87

// if the file exists but we failed to pull it in, log that error at a warning level
if (err.code !== 'MODULE_NOT_FOUND') {
log.warn(`Failed pulling in custom file "${attemptPath}" @ ${customPath}. Error was:`, err)
} else {
log.debug(`No custom file "${attemptPath}" found in ${customPath}. Did you mean to include one?`)
}

This can make it confusing to debug issues with instances using customizations.

Expected Behavior

The full error prints telling me that my require failed.

Actual Behavior

The app incorrectly logs that no custom file exists at that path.

To Reproduce

  • Add a supported file to the custom directory, userAuth.js works well as it is required early in the main app.
  • At the top of that file, add the line require('FAKE_MODULE').
  • Run the app via LOG_LEVEL=debug npm run watch or LOG_LEVEL=debug npm run start.
  • Note the app logs No custom file "userAuth" found in /usr/src/app/custom/userAuth. Did you mean to include one?. This log line is incorrect.

Possible Solution

I think we should be able to check the require stack to make sure that server/utils.js is at the top of the stack. If a file with /custom/ in the path is the first thing in the require stack, we should log the entire error.

@afischer afischer added the bug Something isn't working label Aug 31, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

1 participant