Summary: | koha-shell -c does not propagate the error code | ||
---|---|---|---|
Product: | Koha | Reporter: | Jonathan Druart <jonathan.druart> |
Component: | Architecture, internals, and plumbing | Assignee: | Jonathan Druart <jonathan.druart> |
Status: | CLOSED FIXED | QA Contact: | Testopia <testopia> |
Severity: | normal | ||
Priority: | P5 - low | CC: | 1joynelson, dcook, hayleypelham, lucas, martin.renvoize, nick, tomascohen |
Version: | unspecified | ||
Hardware: | All | ||
OS: | All | ||
Change sponsored?: | --- | Patch complexity: | --- |
Documentation contact: | Documentation submission: | ||
Text to go in the release notes: |
Before this development, the koha-shell script would always return a successful error code, making it hard for the callers to notice there was a problem with the command being run inside the instance's shell.
This development makes koha-shell propagate the running scripts' error code so the caller can take the required actions.
Note: this implies a behaviour change (for good) but a warning should be added to the release notes.
Right now it always returns
|
Version(s) released in: |
20.05.00, 19.11.05, 19.05.10
|
Circulation function: | |||
Bug Depends on: | |||
Bug Blocks: | 25634, 25635 | ||
Attachments: |
Bug 17532: Make koha-shell -c propagate the error code
Bug 17532: Make koha-shell propagate the error code Bug 17532: Make koha-shell propagate the error code Bug 17532: Make koha-shell propagate the error code |
Description
Jonathan Druart
2016-11-01 15:57:54 UTC
Created attachment 57055 [details] [review] Bug 17532: Make koha-shell -c propagate the error code When you execute a command using koha-shell -c, you would like to get the error code of the command you executed. It seems that koha-shell does not do that. Not sure about this, in my last tests it worked as expected. Reviving this one. 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 Created attachment 98808 [details] [review] 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 Do you see any issues this change could cause? This looks pretty sensible and sane to me Created attachment 99918 [details] [review] 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). I should note: I have no idea how widely this script is used, but that will certainly introduced regressions for people using it. For Jenkins that will stop the build if something wrong happens during the insert of the data in the DB (expected behavior). (In reply to Jonathan Druart from comment #9) > I should note: > I have no idea how widely this script is used, but that will certainly > introduced regressions for people using it. > For Jenkins that will stop the build if something wrong happens during the > insert of the data in the DB (expected behavior). I think it is worth changing the (currently) wrong behaviour. It will even help sysadmins using it detect problems. We should of course mention this on the release notes. Good catch (as usual), Jonathan. s/regressions/side-effects ;) Created attachment 99943 [details] [review] 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> Nice work everyone! Pushed to master for 20.05 Backported to 19.11.x for 19.11.05 backported to 19.05.x for 19.05.10 Enhancement will not be backported to 18.11.x series This has a perhaps unforeseen consequence with koha-foreach. Since koha-foreach uses "set -e", if 1 instance runs a command with koha-shell which has a non-zero status, koha-foreach exits. If you have 10 instances and the 1st produces an error, the other 9 instances won't have their commands run at all. (https://www.gnu.org/software/bash/manual/html_node/The-Set-Builtin.html#The-Set-Builtin) I can't imagine that's what we'd want to do? I'll open a new bug report. |