8000 Customizations with import errors can fail with wrong error notice · Issue #289 · nytimes/library · GitHub
[go: up one dir, main page]

Skip to content

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

Open

Description

@afischer

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.

Activity

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

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions

      0