Provide a better error message when target `dependencies` is passed a string, not a list

Review Request #4024 — Created June 25, 2016 and submitted

Eric Ayers
pants
zundel/fix-value-error
3601
b072570...
pants-reviews
benjyw, gmalmquist, kwlzn, nhoward_tw, stuhood

Previously, a malformed target of the form:

target(name='foo', dependencies=':bar')

was parsed as the dependencies ':', 'b', 'a', 'r'. Pants exited cryptically without a path to the BUILD file or indication of which target was wrong:

Exception caught: (<type 'exceptions.ValueError'>)
  ...
  File "/Users/zundel/Src/Pants/src/python/pants/build_graph/address.py", line 84, in parse_spec
    check_target_name(target_name)
  File "/Users/zundel/Src/Pants/src/python/pants/build_graph/address.py", line 71, in check_target_name
    raise ValueError('Spec \{spec\} has no name part'.format(spec=spec))

Exception message: Spec : has no name part

Now we check to see that dependencies is a list, set, or tuple.

Exception message: Invalid target TargetAddressable(target_type=<class 'pants.build_graph.target.Target'>, name=foo, **kwargs=...): dependencies passed to Target constructors must be a sequence of strings, received <type 'str'>
 while executing BUILD file BuildFile(BUILD, FileSystemProjectTree(/Users/zundel/Src/pants))
 Loading addresses from '' failed.
  when translating spec :foo

Also, catch spec parsing error and convert to AddressLookupError to at least get a path to error if something
like this slips through again.

CI is green at https://travis-ci.org/pantsbuild/pants/builds/140202424

Eric Ayers
Garrett Malmquist
  1. Ship It!
  2. 
      
Benjy Weinberger
  1. Ship It!
  2. 
      
Kris Wilson
  1. Ship It!
  2. 
      
Eric Ayers
Review request changed

Status: Closed (submitted)

Change Summary:

Thanks Kris, Garrett, Benjy. Commit fa29329

Loading...