Skip to content

fs.cp throws error with message 'cp returned undefined' #41104

Description

@everett1992

Version

17.2.0

Platform

No response

Subsystem

No response

What steps will reproduce the bug?

$ touch example
$ node -e "require('fs').cp('example', 'example', console.log)"

This throws as expected ERR_FS_CP_EINVAL.

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

Always

What is the expected behavior?

SystemError [ERR_FS_CP_EINVAL]: Invalid src or dest: cp returned EINVAL (src and dest cannot be the same) example
                                                                 ^^^^^^

What do you see instead?

SystemError [ERR_FS_CP_EINVAL]: Invalid src or dest: cp returned undefined (src and dest cannot be the same) example
                                                                 ^^^^^^^^^

Additional information

I'm not sure if this is a bug or intentional behavior but seeing undefined in an error message was unexpected.

throw new ERR_FS_CP_EINVAL({
message: 'src and dest cannot be the same',
path: dest,
syscall: 'cp',
errno: EINVAL,
});

node/lib/internal/errors.js

Lines 225 to 226 in c8a0404

let message = `${prefix}: ${context.syscall} returned ` +
`${context.code} (${context.message})`;

Based on the code should new ERR_FS_CP_EINVAL pass code: EINVAL, or should SystemError use context.code ?? context.errno, or is this the intended behavior?

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

    fsIssues and PRs related to file-system APIs and the fs module.

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions