Skip to content

errros: add a specific error when running commands from plugins#2004

Merged
sergiusens merged 9 commits intocanonical:masterfrom
sergiusens:bugfix/1753965/plugin-command-error
Mar 16, 2018
Merged

errros: add a specific error when running commands from plugins#2004
sergiusens merged 9 commits intocanonical:masterfrom
sergiusens:bugfix/1753965/plugin-command-error

Conversation

@sergiusens
Copy link
Contributor

@sergiusens sergiusens commented Mar 14, 2018

When a plugin fails a horrible traceback is printed because there is no
SnapcraftError class handling the situation.

LP: #1753965
Signed-off-by: Sergio Schvezov sergio.schvezov@canonical.com

  • Have you followed the guidelines for contributing?
  • Have you signed the CLA?
  • If this is a bugfix. Have you checked that there is a bug report open for the issue you are trying to fix on bug reports?
  • If this is a new feature. Have you discussed the design on the forum?
  • Have you successfully run ./runtests.sh static?
  • Have you successfully run ./runtests.sh unit?

@sergiusens sergiusens added this to the 2.40 milestone Mar 14, 2018
@sergiusens sergiusens added the bug label Mar 14, 2018
@sergiusens sergiusens self-assigned this Mar 14, 2018
@sergiusens sergiusens force-pushed the bugfix/1753965/plugin-command-error branch from a30459a to efdd15a Compare March 15, 2018 10:24
@sergiusens sergiusens changed the title errros: add a specific error when running commnds from plugins errros: add a specific error when running commands from plugins Mar 15, 2018
Copy link
Contributor

@kyrofa kyrofa left a comment

Choose a reason for hiding this comment

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

This looks mostly good, although I have a few suggestions inline. One larger suggestion is to also check through the plugins to ensure they're using self.run or self.run_output instead of common.run or common.run_output. I know there's a bit of that in jhbuild, for example. I figure if there's a reason for plugins to not be using self.run et. al, they should go all the way to using subprocess directly.

raise errors.SnapcraftPluginCommandError(
command=cmd, part_name=self.name)

def run_output(self, cmd, cwd=None, **kwargs):
Copy link
Contributor

Choose a reason for hiding this comment

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

How about similar logic here?

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done


fmt = (
'The command {command!r} run for the {part_name!r} part has failed.\n'
'Verify that the part is using the correct parameters and try again.'
Copy link
Contributor

Choose a reason for hiding this comment

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

I think the exit code would be helpful as well. Perhaps something like:

'Failed to run {command!r} for {part_name!r}: '
'Exited with code {exit_code}.\n'
'Verify that the part is using the correct parameters and try again.'

Copy link
Contributor Author

Choose a reason for hiding this comment

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

done

Sergio Schvezov added 6 commits March 15, 2018 15:47
When a plugin fails a horrible traceback is printed because there is no
SnapcraftError class handling the situation.

LP: #1753965
Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
@sergiusens sergiusens force-pushed the bugfix/1753965/plugin-command-error branch from efdd15a to 183d2cb Compare March 15, 2018 19:21
except CalledProcessError as process_error:
raise errors.SnapcraftPluginCommandError(
command=cmd, part_name=self.name,
exit_code=process_error.returncode)
Copy link
Contributor

Choose a reason for hiding this comment

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

Agh sorry, missed this before, but you probably want a from process_error on both of these.

fmt = (
'The command {command!r} run for the {part_name!r} part has failed.\n'
'Exited with exit code {exit_code}.\n'
'Verify that the part is using the correct parameters and try again.'
Copy link
Contributor

Choose a reason for hiding this comment

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

Channeling my inner Leo, this does not meet the agreed-upon error message format which is:

<what>: <why>\n
<how to fix>

It seems to be

<what>\n
<why>\n
<how to fix>

self._run_output([], stderr=subprocess.STDOUT)
except subprocess.CalledProcessError as e:
except (subprocess.CalledProcessError,
SnapcraftPluginCommandError) as e:
Copy link
Contributor

Choose a reason for hiding this comment

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

Note that self._run{_output} here actually goes through common.run{_output} as it's not part of a plugin. You shouldn't need to be handling SnapcraftPluginCommandErrors here.

# in which case we will rely on the `pip install .` ran before
# this.
with contextlib.suppress(subprocess.CalledProcessError):
with contextlib.suppress(subprocess.CalledProcessError,
Copy link
Contributor

Choose a reason for hiding this comment

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

Oh good catch, we would have had issues! However, given that this uses self.run, there's no longer a need to catch CalledProcessError here, is there?

Copy link
Contributor

@kyrofa kyrofa left a comment

Choose a reason for hiding this comment

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

Very nice, thank you for this!

@sergiusens sergiusens merged commit 2308ee4 into canonical:master Mar 16, 2018
@sergiusens sergiusens deleted the bugfix/1753965/plugin-command-error branch March 16, 2018 03:00
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.

2 participants