Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

fix: properly report errors when lock file cannot be parsed #2020

Open
wants to merge 1 commit into
base: main
Choose a base branch
from
Open
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 3 additions & 3 deletions npm/private/pnpm.bzl
Original file line number Diff line number Diff line change
Expand Up @@ -531,12 +531,12 @@ def _parse_lockfile(parsed, err):
A tuple of (importers dict, packages dict, patched_dependencies dict, error string)
"""
if err != None or parsed == None or parsed == {}:
return {}, {}, {}, err
return {}, {}, {}, -1, err if err != None else "could not parse Yaml config"
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm confused, you now return a 5-tuple instead of a 4-tuple, doesn't that require changes at the callsites?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The call sites already expect 5-tuple 😄 — they never see the invalid 4-tuple though because of no errors most of the time

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I see, do you mind correcting the Returns doc above in that case?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This change looks correct, where the -1 is the lockfileVersion.

However I don't think we should have the default "could not parse Yaml config" since I think an empty lockfile is valid? The -1 version number is probably still ok in that case.

Can we add a test for that case that failed previously?


if not types.is_dict(parsed):
return {}, {}, {}, "lockfile should be a starlark dict"
return {}, {}, {}, -1, "lockfile should be a starlark dict"
if not parsed.get("lockfileVersion", False):
return {}, {}, {}, "expected lockfileVersion key in lockfile"
return {}, {}, {}, -1, "expected lockfileVersion key in lockfile"

# Lockfile version may be a float such as 5.4 or a string such as '6.0'
lockfile_version = str(parsed["lockfileVersion"])
Expand Down
Loading