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

Cryptic error when package.json is missing a name #20859

Open
yjabri opened this issue Apr 29, 2024 · 1 comment
Open

Cryptic error when package.json is missing a name #20859

yjabri opened this issue Apr 29, 2024 · 1 comment
Labels
backend: JavaScript JavaScript backend-related issues bug diagnostics Poor diagnostics, error messages that could be improved

Comments

@yjabri
Copy link
Contributor

yjabri commented Apr 29, 2024

Is your feature request related to a problem? Please describe.
I was trying out the experimental JavaScript backend and running some "unfriendly" behavior. I've included a minimal reproduction repo to try the following in.

Run pants tailor ::. It populates foo/BUILD with


package_json()

Run pants tailor :: again. You'll get

$ pants tailor ::
14:56:17.68 [ERROR] 1 Exception encountered:

Engine traceback:
  in `tailor` goal

KeyError: 'name'

In a non minimal repo I had package_json() populate like package_json(name="foo0") since I had a python distribution with the same name. Given KeyError: 'name' it feels like tailor is writing an invalid target to the BUILD file. Also running pants help targets package_json doesn't enumerate a name field.

It took me some time to realize this had nothing to do with the BUILD file but instead that my package.json was missing a name.

Describe the solution you'd like
A more explicit message should be given to the caller that package.json needs to have a name the first time pants tailor (or any goal that consumes the file) is called.

Describe alternatives you've considered

Additional context

@yjabri yjabri changed the title Cryptic Error When package.json is missing a Name Cryptic error when package.json is missing a name Apr 29, 2024
@huonw huonw added bug backend: JavaScript JavaScript backend-related issues diagnostics Poor diagnostics, error messages that could be improved and removed enhancement labels Apr 29, 2024
@huonw
Copy link
Contributor

huonw commented Apr 29, 2024

Thanks for the reproducer. I can reproduce.


For someone debugging, here's the stack trace output pants --print-stacktrace tailor ::

09:44:13.39 [ERROR] 1 Exception encountered:

Engine traceback:
  in root
    ..
  in pants.core.goals.tailor.tailor
    `tailor` goal

Traceback (most recent call last):
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/core/goals/tailor.py", line 650, in tailor
    specs_paths = await Get(SpecsPaths, Specs, specs)
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 124, in __await__
    result = yield self
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/specs_rules.py", line 313, in resolve_specs_paths
    unfiltered_include_targets, ignore_targets, include_paths, ignore_paths = await MultiGet(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 436, in MultiGet
    return await _MultiGet((__arg0, __arg1, __arg2, __arg3))
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 174, in __await__
    result = yield self.gets
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/specs_rules.py", line 258, in resolve_addresses_from_raw_specs
    without_file_owners, with_file_owners = await MultiGet(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 406, in MultiGet
    return await _MultiGet((__arg0, __arg1))
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 174, in __await__
    result = yield self.gets
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/specs_rules.py", line 183, in addresses_from_raw_specs_without_file_owners
    target_parametrizations_list = await MultiGet(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 376, in MultiGet
    return await _MultiGet(tuple(__arg0))
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 174, in __await__
    result = yield self.gets
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/graph.py", line 349, in resolve_target_parametrizations
    all_generated = await MultiGet(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 376, in MultiGet
    return await _MultiGet(tuple(__arg0))
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 174, in __await__
    result = yield self.gets
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/backend/javascript/package_json.py", line 735, in all_package_json
    await Get(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 124, in __await__
    result = yield self
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/backend/javascript/package_json.py", line 709, in read_package_jsons
    await MultiGet(
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 376, in MultiGet
    return await _MultiGet(tuple(__arg0))
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/engine/internals/selectors.py", line 174, in __await__
    result = yield self.gets
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/backend/javascript/package_json.py", line 688, in parse_package_json
    name=parsed_package_json["name"],
  File "/Users/huon/Library/Caches/nce/f46d2c12132bad9c27e0dd509186c190371abfe1add7e5ca42245466f35bea81/bindings/venvs/2.20.0/lib/python3.9/site-packages/pants/util/frozendict.py", line 77, in __getitem__
    return self._data[k]
KeyError: 'name'

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
backend: JavaScript JavaScript backend-related issues bug diagnostics Poor diagnostics, error messages that could be improved
Projects
None yet
Development

No branches or pull requests

2 participants