Skip to content

Cannot set property message of ... which has only a getter when an error happens during instrumentation hook being require'd #54417

Open
@SeriousBug

Description

@SeriousBug

Verify canary release

  • I verified that the issue exists in the latest Next.js canary release

Provide environment information

Operating System:
      Platform: linux
      Arch: x64
      Version: #1 ZEN SMP PREEMPT_DYNAMIC Tue, 08 Aug 2023 22:13:48 +0000
    Binaries:
      Node: 18.17.1
      npm: 9.6.7
      Yarn: 1.22.19
      pnpm: 8.6.12
    Relevant Packages:
      next: 13.4.20-canary.2
      eslint-config-next: 13.4.13
      react: 18.2.0
      react-dom: 18.2.0
      typescript: 5.1.6
    Next.js Config:
      output: N/A

Which area(s) of Next.js are affected? (leave empty if unsure)

No response

Link to the code that reproduces this issue or a replay of the bug

https://github.com/SeriousBug/nextjs-error-repro

To Reproduce

Enable instrumentationHook experimental feature, then in the instrumentation.ts throw an error where the message field is a getter. This will cause the error Cannot set property message of ... which has only a getter. A similar error occurs if the error was not an object.

Describe the Bug

The bug is caused by this line which incorrectly assumes that the error must have a message field, which results inside the catch block:

err.message = `An error occurred while loading instrumentation hook: ${err.message}`

I encountered this issue because I was parsing data with Zod at the top level of instrumentation.ts, which throws a custom error with a getter message field.

Expected Behavior

A concise error message should still be displayed if the message field can not be overwritten.

Which browser are you using? (if relevant)

No response

How are you deploying your application? (if relevant)

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    InstrumentationRelated to Next.js Instrumentation.bugIssue was opened via the bug report template.

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions