Skip to content

util: fix inspection of errors with tampered stack property for node v10 #33948

Description

@analog-nico

This is an error report for node v10 which has already been fixed for node v12 and may make sense to fix in node v10 as well. The fix in node v12 could have been made via pull request #30576 .

  • Version: 10.21.0
  • Platform: Mac OS X
  • Subsystem: util

What steps will reproduce the bug?

'use strict'

let util = require('util')

let err1 = new Error()
let err2 = new Error()

err2.stack = String(err2.stack).split('\n') // This breaks it.

util.inspect(err1) // -> OK
util.inspect(err2) // -> OK
util.inspect({ err1 }) // -> OK
util.inspect({ err2 }) // -> TypeError: formatError(...).replace is not a function

How often does it reproduce? Is there a required condition?

Every time in node v10.21.0. Never in node v12.16.1.

What is the expected behavior?

The err2.stack array is inspected as an array would usually be inspected.

What do you see instead?

util.inspect({ err2 }) throws this error: TypeError: formatError(...).replace is not a function

Additional information

Feel free to close if such a fix is not within the scope of the LTS maintenance phase in which node v10 is currently in.

Activity

  1. ZYSzys commented on Jun 21, 2020

    @ZYSzys
    Member

    /cc @nodejs/release, maybe we could backport #30576 to next v10 LTS release.

  2. added
    utilIssues and PRs related to the built-in util module.
    on Jun 21, 2020
  3. richardlau commented on Jul 2, 2020

    @richardlau
    Member

    #30576 doesn't land cleanly on v10.x-staging so would need a manual backport.

  4. ZYSzys commented on Jul 3, 2020

    @ZYSzys
    Member

    However, I found if we want to land #30576, we need to land #26923 first, which was marked as dont-land-on-v10.x.

    /cc @BridgeAR

  5. BridgeAR commented on Jul 3, 2020

    @BridgeAR
    Member

    @ZYSzys #26923 should not be backported. The actual fix is to change the formatError function as it is in v10 to return value.stack ? String(value.stack) : errorToString(value);

  6. BridgeAR commented on Mar 19, 2021

    @BridgeAR
    Member

    I am closing this as it's not a security issue and Node.js 10 is soon not maintained anymore.

    @analog-nico I hope you were able to move to Node.js 12 or above by now!

  7. analog-nico commented on Mar 21, 2021

    @analog-nico
    Author

    @BridgeAR Sounds good! I made sure to not run into this issue in my code and upgrading node makes sense anyways. Thanks!

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

    utilIssues and PRs related to the built-in util module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions