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 crash if pants.ini is missing in the buildroot #7452

Merged

Conversation

Projects
None yet
3 participants
@Eric-Arellano
Copy link
Contributor

commented Mar 29, 2019

Problem

If pants.ini is not present, then Pants will crash with this error:

timestamp: 2019-03-28T18:16:34.356612
Exception caught: (exceptions.IOError)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/bin/pants", line 10, in <module>
    sys.exit(main())
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 85, in main
    PantsLoader.run()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 81, in run
    cls.load_and_execute(entrypoint)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 74, in load_and_execute
    entrypoint_main()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_exe.py", line 39, in main
    PantsRunner(exiter, start_time=start_time).run()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_runner.py", line 39, in run
    options_bootstrapper = OptionsBootstrapper.create(env=self._env, args=self._args)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 133, in create
    config_files_products = [filecontent_for(p) for p in config_file_paths]
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 106, in filecontent_for
    return FileContent(ensure_text(path), read_file(path))
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/util/dirutil.py", line 155, in read_file
    with open(filename, mode) as f:

Exception message: [Errno 2] No such file or directory: '/Users/eric/DocsLocal/code/projects/setup/pants.ini'

This does not appear to be by design. Notably, we allow an empty pants.ini without any issue. There is no meaningful difference between an empty pants.ini from a non-existent pants.ini, so this seems to be a bug.

Solution

First check if pants.ini exists before adding it to the list of config files.

This also allows us to refactor ./pants generate-pants-ini from #7448 to create a new pants.ini, rather than requiring the user to make it. This allows us to simplify our setup instructions even more by removing the touch pants.ini instruction.

Properly fix the issue
John pointed out we only want to allow a missing pants.ini. If the user specifies other connfig files through --pants-config-file, then those must exist and we should error if they do not.

So, we move the fix into get_config_file_paths() rather than filecontent_for()

@Eric-Arellano Eric-Arellano merged commit 645a22e into pantsbuild:master Mar 29, 2019

1 check passed

continuous-integration/travis-ci/pr The Travis CI build passed
Details

@Eric-Arellano Eric-Arellano deleted the Eric-Arellano:allow-missing-pants-ini branch Mar 29, 2019

stuhood added a commit that referenced this pull request Mar 29, 2019

Fix crash if pants.ini is missing in the buildroot (#7452)
### Problem
If `pants.ini` is not present, then Pants will crash with this error:

```
timestamp: 2019-03-28T18:16:34.356612
Exception caught: (exceptions.IOError)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/bin/pants", line 10, in <module>
    sys.exit(main())
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 85, in main
    PantsLoader.run()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 81, in run
    cls.load_and_execute(entrypoint)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_loader.py", line 74, in load_and_execute
    entrypoint_main()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_exe.py", line 39, in main
    PantsRunner(exiter, start_time=start_time).run()
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/bin/pants_runner.py", line 39, in run
    options_bootstrapper = OptionsBootstrapper.create(env=self._env, args=self._args)
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 133, in create
    config_files_products = [filecontent_for(p) for p in config_file_paths]
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/option/options_bootstrapper.py", line 106, in filecontent_for
    return FileContent(ensure_text(path), read_file(path))
  File "/Users/eric/.cache/pants/setup/bootstrap-Darwin-x86_64/unspecified_py27/lib/python2.7/site-packages/pants/util/dirutil.py", line 155, in read_file
    with open(filename, mode) as f:

Exception message: [Errno 2] No such file or directory: '/Users/eric/DocsLocal/code/projects/setup/pants.ini'
```

This does not appear to be by design. Notably, we allow an empty `pants.ini` without any issue. There is no meaningful difference between an empty `pants.ini` from a non-existent `pants.ini`, so this seems to be a bug.

### Solution
First check if `pants.ini` exists before adding it to the list of config files.

This also allows us to refactor `./pants generate-pants-ini` from #7448 to create a new `pants.ini`, rather than requiring the user to make it. This allows us to simplify our setup instructions even more by removing the `touch pants.ini` instruction.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.