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

Update Python runner to throw a more user-friendly exception on missing pack config item #4014

Merged
merged 11 commits into from
Feb 28, 2018

Conversation

Kami
Copy link
Member

@Kami Kami commented Feb 27, 2018

This pull request updates Python runner so it throws a more user-friendly exception when a script tries to access a key in self.config dictionary which doesn't exist.

@LindsayHill did a good job of adding a note to most pack README.md files which says user need to run st2ctl reload --register-configs after adding / modifying configs, but it's still easy to miss / forget that step so we should throw as user-friendly exception as possible.

Before:

python ./st2client/st2client/shell.py run examples.print_config
id: 5a9540d60640fd0bc9dbf6b4
status: failed
parameters: None
result: 
  exit_code: 1
  result: None
  stderr: "Traceback (most recent call last):
  File "/data/stanley/contrib/runners/python_runner/python_runner/python_action_wrapper.py", line 356, in <module>
    obj.run()
  File "/data/stanley/contrib/runners/python_runner/python_runner/python_action_wrapper.py", line 213, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/examples/actions/print_config.py", line 9, in run
    api_user = self.config['api_user']
KeyError: 'api_user'
"
  stdout: '=========
    '

After:

python ./st2client/st2client/shell.py run examples.print_config
id: 5a9540a90640fd0bc9dbf6b1
status: failed
parameters: None
result: 
  exit_code: 1
  result: None
  stderr: "Traceback (most recent call last):
  File "/data/stanley/contrib/runners/python_runner/python_runner/python_action_wrapper.py", line 356, in <module>
    obj.run()
  File "/data/stanley/contrib/runners/python_runner/python_runner/python_action_wrapper.py", line 213, in run
    output = action.run(**self._parameters)
  File "/opt/stackstorm/packs/examples/actions/print_config.py", line 9, in run
    api_user = self.config['api_user']
  File "/data/stanley/contrib/runners/python_runner/python_runner/python_action_wrapper.py", line 156, in __getitem__
    raise ValueError(msg)
ValueError: 
Config for pack "examples" is missing key "api_user".
Make sure that the config file exists on disk (/opt/stackstorm/configs/examples.yaml) and contains that key.

Also make sure you run "st2ctl reload --register-configs" when you add a
config and after every change you make to the config.

"
  stdout: '=========
    '

TODO

  • Tests

@Kami Kami added this to the 2.7.0 milestone Feb 27, 2018
@Kami Kami assigned Kami, lakshmi-kannan and LindsayHill and unassigned Kami Feb 27, 2018
@Kami Kami changed the title [WIP] Update Python runner to throw a more user-friendly exception on missing pack config item Update Python runner to throw a more user-friendly exception on missing pack config item Feb 28, 2018

Also make sure you run "st2ctl reload --register-configs" when you add a
config and after every change you make to the config.
"
Copy link
Member

Choose a reason for hiding this comment

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

that does not look right

Copy link
Member Author

Choose a reason for hiding this comment

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

Hm, what do you mean? Am I missing something?

Copy link
Member Author

Choose a reason for hiding this comment

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

Never mind, I see it now - there is an extra double quote here.

Copy link
Member Author

Choose a reason for hiding this comment

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

Fixed in 4b082b3.

@Kami Kami merged commit 58bfed3 into master Feb 28, 2018
@Kami Kami deleted the pack_config_missing_dict_entry_friendly_error branch February 28, 2018 15:10
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

4 participants