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

Wrap errors in _error key #5

Merged
merged 2 commits into from Sep 4, 2019
Merged

Wrap errors in _error key #5

merged 2 commits into from Sep 4, 2019

Conversation

nicklewis
Copy link
Contributor

Previously, the task helper would rescue errors in the run method and
simply print their hashified version. This caused Bolt to synthesize its own
_error object (simply stating the task failed and its exit code) which
took precedence over the actual underlying cause.

We now properly wrap the result in _error so Bolt knows that it should
display that information to the user.

Previously, the task helper would rescue errors in the `run` method and
simply print their hashified version. This caused Bolt to synthesize its own
`_error` object (simply stating the task failed and its exit code) which
took precedence over the actual underlying cause.

We now properly wrap the result in `_error` so Bolt knows that it should
display that information to the user.
@nicklewis nicklewis requested review from lucywyman and a team and removed request for lucywyman August 30, 2019 18:12
@lucywyman
Copy link
Contributor

This seems like a great change, though it'll also need a 1.0 release. I don't think that will be a problem?

@nicklewis
Copy link
Contributor Author

The beauty of semver is that pre-1.0 there are no rules! And honestly I would call this a bug. It's a bug that a user or two may rely on, but it's pretty unambiguously a bug.

@lucywyman
Copy link
Contributor

I guess I don't see the harm in doing a 1.0. The risk is that there are people who rely on it who this breaks, and even if it doesn't break the letter of the semver law it feels like it'll give people a bad day. That said I guess folks will have to pin in their puppetfile either way, so maybe it doesn't matter?

exit 1
rescue StandardError => e
error = TaskHelper::Error.new(e.message, e.class.to_s, e.backtrace)
STDOUT.print(error.to_h.to_json)
STDOUT.print({ _error: error.to_h }.to_json)
Copy link
Member

Choose a reason for hiding this comment

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

Would it be worth adding a failure status? That way with human outputter there is not an empty hash under the error message.

Suggested change
STDOUT.print({ _error: error.to_h }.to_json)
STDOUT.print({status: 'failure', _error: error.to_h }.to_json)
cas@cas-ThinkPad-T460p:~/working_dir/bolt$ bolt task run test::ruby_task_helper name=hi -t localhost
Started on localhost...
Failed on localhost:
  ooops task failed
  {
    "status": "failure"
  }
Failed on 1 node: localhost
Ran on 1 node in 0.19 sec

Copy link
Member

Choose a reason for hiding this comment

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

@lucywyman @nicklewis I think we agree on the version. What do ya'll think about the status key?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

I don't like the status key because we already define success/failure as part of the task spec. Also, there is no status key in the success case, which mean it's not something you can actually rely on.

If the problem is a superfluous empty hash being printed after the error message, we could fix that in bolt rather than changing the result here.

donoghuc added a commit to donoghuc/puppetlabs-python_task_helper that referenced this pull request Sep 4, 2019
Previously, the task helper would rescue errors in the run method and
simply print their hashified version. This caused Bolt to synthesize its own
_error object (simply stating the task failed and its exit code) which
took precedence over the actual underlying cause.

We now properly wrap the result in _error so Bolt knows that it should
display that information to the user.

Porting over the changes from puppetlabs/puppetlabs-ruby_task_helper#5
@donoghuc
Copy link
Member

donoghuc commented Sep 4, 2019

I ported over this update to the python task helper (and included the status: failure key, based on what we decide here I can remove it if necessary).

I agree this is a bug that does not need a x release. If you look at the CHANGELOG every y release has been a bug fix kind of like this. So I think we just bump the y.

Copy link
Member

@donoghuc donoghuc left a comment

Choose a reason for hiding this comment

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

I'm going to merge this and put up a PR for release prep.

@donoghuc donoghuc merged commit 39aff1b into master Sep 4, 2019
donoghuc added a commit to donoghuc/puppetlabs-python_task_helper that referenced this pull request Sep 4, 2019
Previously, the task helper would rescue errors in the run method and
simply print their hashified version. This caused Bolt to synthesize its own
_error object (simply stating the task failed and its exit code) which
took precedence over the actual underlying cause.

We now properly wrap the result in _error so Bolt knows that it should
display that information to the user.

Porting over the changes from puppetlabs/puppetlabs-ruby_task_helper#5
@puppet-cla-assistant puppet-cla-assistant deleted the wrap-error-in-_error-key branch February 24, 2021 17:09
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

3 participants