Bug 17532: Make koha-shell propagate the error code
authorJonathan Druart <jonathan.druart@bugs.koha-community.org>
Thu, 13 Feb 2020 11:03:36 +0000 (12:03 +0100)
committerMartin Renvoize <martin.renvoize@ptfs-europe.com>
Tue, 3 Mar 2020 09:15:57 +0000 (09:15 +0000)
commitab94a12ee46c511b5c09326d37925081996f89aa
tree99ff9016f0dbcee87deb35ec3610fca6b9408b53
parent9a9e9fb95e52390451d774835e60903a89647a4d
Bug 17532: Make koha-shell propagate the error code

Context: I am trying to make koha-misc4dev stop when something wrong happens.
Basically we do not want the process to continue of the DB has not been populated correctly.
It will make the errors easier to catch.

The issue: Say a script that will return an error (die in perl for an easy example),
koha-shell will not return the 255 error code, but 0 instead.
The caller cannot know something wrong happened

The solution is to propagate the error and make koha-shell return the same error code
as the command it executed

An example:
=== t.pl ===
die('something wrong');

% perl t.pl;echo $?
something wrong at t.pl line 1.
255

% sudo koha-shell kohadev -p -c 'perl xxx.pl' ; echo $?
something wrong at xxx.pl line 1.
0

Signed-off-by: Tomas Cohen Arazi <tomascohen@theke.io>
Tested it with
  $ sudo debian/scripts/koha-shell kohadev -c 'exit 8'
  $ echo $?
  8
The unpatched version returns 0 (forgets about the error code).

Signed-off-by: Martin Renvoize <martin.renvoize@ptfs-europe.com>
debian/scripts/koha-shell