Skip to content

Commit

Permalink
meta: friendlier message for incorrect app command (#2272)
Browse files Browse the repository at this point in the history
Provide a nicer error for when the command entires under
an specific application cannot be found.

Also, for future proofing, ensure a warning is raised when these
commands are not relative to the prime directory.

LP: #1791175
Fixes SNAPCRAFT-26
Fixes SNAPCRAFT-3M
Fixes SNAPCRAFT-3T
Fixes SNAPCRAFT-3W
Fixes SNAPCRAFT-43

Signed-off-by: Sergio Schvezov <sergio.schvezov@canonical.com>
  • Loading branch information
sergiusens committed Sep 14, 2018
1 parent de1fe27 commit 65ba888
Show file tree
Hide file tree
Showing 4 changed files with 19 additions and 7 deletions.
6 changes: 2 additions & 4 deletions snapcraft/internal/errors.py
Expand Up @@ -167,10 +167,8 @@ class InvalidAppCommandError(SnapcraftError):
fmt = (
"Failed to generate snap metadata: "
"The specified command {command!r} defined in the app {app!r} does "
"not exist or is not executable"
# FIXME split the errors to include in the message how to fix them.
# https://bugs.launchpad.net/snapcraft/+bug/1727425
# --elopio - 2017-10-25
"not exist or is not executable.\n"
"Ensure that {command!r} is relative to the prime directory."
)

def __init__(self, command, app):
Expand Down
2 changes: 2 additions & 0 deletions snapcraft/internal/meta/_snap_packaging.py
Expand Up @@ -581,6 +581,8 @@ def _wrap_app(self, name, app):
for k in cmds:
try:
app[k] = self._wrap_exe(app[k], "{}-{}".format(k, name))
except FileNotFoundError:
raise errors.InvalidAppCommandError(command=app[k], app=app)
except meta_errors.CommandError as e:
raise errors.InvalidAppCommandError(str(e), name)

Expand Down
3 changes: 2 additions & 1 deletion tests/unit/test_errors.py
Expand Up @@ -271,7 +271,8 @@ class ErrorFormattingTestCase(unit.TestCase):
"expected_message": (
"Failed to generate snap metadata: "
"The specified command 'test-command' defined in the app "
"'test-app' does not exist or is not executable"
"'test-app' does not exist or is not executable.\n"
"Ensure that 'test-command' is relative to the prime directory."
),
},
),
Expand Down
15 changes: 13 additions & 2 deletions tests/unit/test_meta.py
Expand Up @@ -1216,8 +1216,7 @@ def test_create_meta_with_grade(self):
)


# TODO this needs more tests.
class WrapExeTestCase(unit.TestCase):
class BaseWrapTest(unit.TestCase):
def setUp(self):
super().setUp()

Expand All @@ -1239,6 +1238,18 @@ def setUp(self):
self.packager = _snap_packaging._SnapPackaging(config)
self.packager._is_host_compatible_with_base = True


class WrapAppTest(BaseWrapTest):
def test_app_not_found(self):
self.assertRaises(
errors.InvalidAppCommandError,
self.packager._wrap_apps,
apps=dict(app=dict(command="test-command")),
)


# TODO this needs more tests.
class WrapExeTest(BaseWrapTest):
@patch("snapcraft.internal.common.assemble_env")
def test_wrap_exe_must_write_wrapper(self, mock_assemble_env):
mock_assemble_env.return_value = "PATH={0}/part1/install/usr/bin:{0}/part1/install/bin".format(
Expand Down

0 comments on commit 65ba888

Please sign in to comment.