Skip to content

Unclear Error Message When package.json Lacks version Key #241

Open
@ElayGelbart

Description

@ElayGelbart

When running various CLI commands using the yalc package, if the package.json file does not contain a version key, the resulting error message is unclear and misleading. It seems that the lack of a version key may not be properly handled, leading to an unexpected error in path operations.

Steps to Reproduce

Ensure package.json does not include a version key.
Run a CLI command such as yalc publish or yalc add.
Observe the error output.

Expected Behavior

The tool should either handle the missing version key gracefully by providing a clear error message indicating the absence of the version key or handle the operation assuming defaults.

Actual Behavior

The tool throws a TypeError related to path operations, which does not clearly communicate the issue related to the missing version key in package.json.

Error Output

TypeError [ERR_INVALID_ARG_TYPE]: The "path" argument must be of type string. Received undefined
    at new NodeError (node:internal/errors:399:5)
    at validateString (node:internal/validators:163:11)
    at Object.join (node:path:1172:7)
    at <file path removed for privacy>
    at new Promise (<anonymous>)
    at __awaiter (<file path removed for privacy>)
    at exports.copyPackageToStore (<file path removed for privacy>) {
  code: 'ERR_INVALID_ARG_TYPE'
}

(Note: File paths and user identifiers have been removed for privacy.)

Additional Information

Node version: v18.16.0
yalc version: 1.0.0-pre.53
Operating System: MacOS

Suggested Fix

A potential improvement could be to validate the existence of the version key before proceeding with operations that depend on it, and if it is missing, throw a clear and descriptive error message.

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