Clear error when specifying a non existing command #350

Merged
merged 1 commit into from Mar 1, 2016

Conversation

Projects
None yet
3 participants
Collaborator

sergiusens commented Feb 29, 2016

When a command is supposed to be in PATH, make sure
the error is clear.

LP: #1550496

Signed-off-by: Sergio Schvezov sergio.schvezov@ubuntu.com

@@ -549,3 +549,13 @@ def test_exe_is_in_path(self, run_mock):
wrapper_contents = wrapper_file.read()
self.assertEqual(expected, wrapper_contents)
+
+ def test_command_does_not_exist(self):
@kyrofa

kyrofa Feb 29, 2016

Member

Can you add a test for a file that exists but is simply not executable as well?

Member

kyrofa commented Feb 29, 2016

I'd like one more test in there, but other than that this looks great 😃 .

snapcraft/meta.py
@@ -222,10 +218,28 @@ def _wrap_exe(command, basename=None):
return os.path.relpath(wrappath, snap_dir)
+def _find_bin(binary, basedir):
+ # If it doesn't exist it might be in the path
+ logger.debug('Checking to see if {!r} is in the $PATH'.format(binary))
@elopio

elopio Feb 29, 2016

Member

s/Checking to see if/Checking if

@kyrofa

kyrofa Feb 29, 2016

Member

s/Checking if/Checking that/ in that case

@sergiusens

sergiusens Feb 29, 2016

Collaborator

meh, old code :-P

Collaborator

sergiusens commented Feb 29, 2016

@kyrofa done

Member

kyrofa commented Feb 29, 2016

Looks perfect! 👍

Collaborator

sergiusens commented Feb 29, 2016

@kyrofa just for the kicks I've added a sunny day scenario as well

snapcraft/meta.py
+ except CommandError as e:
+ raise EnvironmentError(
+ 'The specified command {!r} defined in {!r} does '
+ 'not exist'.format(str(e), app))
@elopio

elopio Feb 29, 2016

Member

So, should it be: does not exist or is not executable ?

@kyrofa

kyrofa Feb 29, 2016

Member

I guess that's a good question. Are the exit codes 126 and 127? We can probably print the right message here depending.

@sergiusens

sergiusens Feb 29, 2016

Collaborator

If it is not executable it inherently does not exist from a "command" PoV.

@sergiusens

sergiusens Feb 29, 2016

Collaborator

@kyrofa and @elopio

From the manpage

       1      if  one  or  more  specified commands is nonexistent or not exe-
              cutable

I'll make the change, too bad since travis already ran 😩
To be fair, people using the copy plugin get what they deserve! This would not happen when using a proper build system 😉

snapcraft/tests/test_meta.py
+ "defined in 'app1' does not exist",
+ str(raised.exception))
+
+ def test_command_found(self):
@kyrofa

kyrofa Feb 29, 2016

Member

Oh yeah. That's probably a good idea 😛 .

Clear error when specifying a non existing command
When a command is supposed to be in PATH, make sure
the error is clear.

LP: #1550496

Signed-off-by: Sergio Schvezov <sergio.schvezov@ubuntu.com>

sergiusens added a commit that referenced this pull request Mar 1, 2016

Merge pull request #350 from sergiusens/bugfix/1550496/exe-error
Clear error when specifying a non existing command

@sergiusens sergiusens merged commit 2886cc4 into snapcore:master Mar 1, 2016

4 checks passed

Examples tests Success 13 tests run, 0 skipped, 0 failed.
Details
autopkgtest Success No test results found.
Details
continuous-integration/travis-ci/pr The Travis CI build passed
Details
coverage/coveralls Coverage increased (+0.03%) to 94.777%
Details

@sergiusens sergiusens deleted the sergiusens:bugfix/1550496/exe-error branch Mar 1, 2016

smoser pushed a commit to smoser/snapcraft that referenced this pull request Sep 14, 2016

Merge pull request #350 from hglkrijger/master
correct logic for dd fallback

kalikiana pushed a commit to kalikiana/snapcraft that referenced this pull request Apr 6, 2017

Merge pull request #350 from sergiusens/bugfix/1550496/exe-error
Clear error when specifying a non existing command
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment