Improve exception handling for bad option values, such as when PANTS_CONFIG_OVERRIDE="pants.ini" exists in the environment.

Review Request #3087 - Created Nov. 6, 2015 and submitted

Information
Kris Wilson
pants
kwlzn/config_override_eval
2500, 2510
Reviewers
pants-reviews
benjyw, nhoward_tw
  • Catch all exception types during option value eval() to ensure ParseError is reliably raised.
  • Add option name context to the error message and mention environment variables to give users an actionable hint as to whats gone wrong.
  • Test coverage.

Fixes #2500

https://travis-ci.org/pantsbuild/pants/builds/89592425


before

[illuminati pants-release (master)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="blah.ini" ./pants
Exception caught: (<type 'exceptions.NameError'>)
...
Exception message: name 'blah' is not defined

[illuminati pants-release (master)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="True" ./pants
Exception caught: (<class 'pants.option.errors.ParseError'>)
...
Exception message: The value is not of the expected type(s): list, tuple:
Given the following raw value that evaluated to type bool:
1: True

[illuminati pants-release (master)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="1" ./pants
Exception caught: (<class 'pants.option.errors.ParseError'>)
...
Exception message: The value is not of the expected type(s): list, tuple:
Given the following raw value that evaluated to type int:
1: 1

after

[illuminati pants (kwlzn/config_override_eval)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="blah.ini" ./pants
Exception caught: (<class 'pants.option.errors.ParseError'>)
...
Exception message: Error computing value for --config-override (may also be from PANTS_* environment variables):
ParseError: The value cannot be evaluated as a literal expression: name 'blah' is not defined
Given raw value:
1: blah.ini

[illuminati pants (kwlzn/config_override_eval)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="True" ./pants
Exception caught: (<class 'pants.option.errors.ParseError'>)
...
Exception message: Error computing value for --config-override (may also be from PANTS_* environment variables):
ParseError: The value is not of the expected type(s): list, tuple:
Given the following raw value that evaluated to type bool:
1: True

[illuminati pants (kwlzn/config_override_eval)]$ PANTS_DEV=1 PANTS_CONFIG_OVERRIDE="1" ./pants
Exception caught: (<class 'pants.option.errors.ParseError'>)
...
Exception message: Error computing value for --config-override (may also be from PANTS_* environment variables):
ParseError: The value is not of the expected type(s): list, tuple:
Given the following raw value that evaluated to type int:
1: 1

Issues

  • 0
  • 3
  • 1
  • 4
Description From Last Updated
Benjy Weinberger
Matt Olsen
Kris Wilson
Benjy Weinberger
Kris Wilson
Review request changed

Status: Closed (submitted)

Change Summary:

Thanks gents. submitted @ 14a37f5a546342d3b341d7a03e1780a590405a92

Loading...