Skip to content

Fix error handling and logging #3236

@nikgraf

Description

@nikgraf

Describe the bug

When you render a PDF in node the actual error gets logged to console.error and a different error gets thrown TypeError: Cannot read properties of null. This has two issues:

  1. When logging errors to Sentry you always get the same error.
  2. When using a formatted logger the console.error pollutes the stdout/stderror with non-formated logs.

When debugging I learned, but rethrowing the error instead of logging it here it worked as expected:

logRecoverableError, // onUncaughtError
logRecoverableError, // onCaughtError
logRecoverableError, // onRecoverableError

I have two suggestions and would be happy to open PRs in case there is interest for them:

  1. instead of console.log/warn/error allow to pass in a logger that by default is console
  2. instead of logging the reconciler errors they are re-thrown

To Reproduce
Steps to reproduce the behavior including code snippet (if applies):

Add this code in a component:

Example in a component:

if ('test' in {}.test2) {
  console.log('Did not fail');
}

and render the PDF in node e.g. https://github.com/diegomura/react-pdf/blob/master/e2e/node-esm/index.js

You can make use of react-pdf REPL to share the snippet

Expected behavior
A clear and concise description of what you expected to happen.

Screenshots
If applicable, add screenshots to help explain your problem.

Desktop (please complete the following information):

  • OS: MacOS
  • Node
  • React-pdf version "@react-pdf/renderer": "^4.3.0"

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions