[Bug 44315] New: Koha::Sitemapper exits with status 0 on errors
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 Bug ID: 44315 Summary: Koha::Sitemapper exits with status 0 on errors Initiative type: --- Sponsorship --- status: Product: Koha Version: Main Hardware: All OS: All Status: NEW Severity: normal Priority: P5 - low Component: Command-line Utilities Assignee: koha-bugs@lists.koha-community.org Reporter: tomascohen@gmail.com QA Contact: testopia@bugs.koha-community.org CC: jake.deery@openfifth.co.uk, robin@catalyst.net.nz Target Milestone: --- When Koha::Sitemapper cannot do its job it prints a message to STDOUT and calls exit, which ends the whole process with status 0: * Koha::Sitemapper: the "dir" attribute trigger, when the directory is not valid ("This is not a valid directory: ...") * Koha::Sitemapper::Writer::_writer_create, when a sitemap file cannot be created ("Impossible to create file: ...") As a result misc/cronjobs/sitemap.pl reports success although no sitemap was written, so cron jobs and wrappers (e.g. koha-sitemap) cannot detect the failure. A library module should not call exit at all. To reproduce: perl misc/cronjobs/sitemap.pl --dir /nonexistent ; echo $? => "This is not a valid directory: /nonexistent" on STDOUT, exit status 0 Expected: die with the reason on STDERR (including the system error when a file cannot be created), so sitemap.pl exits with a non-zero status. -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 --- Comment #1 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212744 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212744&action=edit Bug 44315: Add regression tests This patch adds tests for Koha::Sitemapper's error handling: when the target directory is not valid, or a sitemap file cannot be created, it must die instead of exiting the process with status 0. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Sitemapper.t => FAIL: Tests fail! The test file stops when creating the Sitemapper with an invalid directory: Koha::Sitemapper calls exit 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 --- Comment #2 from Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> --- Created attachment 212745 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212745&action=edit Bug 44315: Make Koha::Sitemapper die on errors instead of exiting Koha::Sitemapper (invalid 'dir') and Koha::Sitemapper::Writer (sitemap file cannot be created) printed a message to STDOUT and called exit, which ends the process with status 0. sitemap.pl then reported success although no sitemap was written, so callers like koha-sitemap could not notice the failure. This patch makes them die instead, with the reason on STDERR (including the system error when a file cannot be created), so sitemap.pl exits with a non-zero status. Test plan: 1. Apply the regression tests patch and run: $ ktd --shell k$ prove t/db_dependent/Sitemapper.t => FAIL: The test file stops early 2. Apply this patch and repeat 1 => SUCCESS: Tests pass! 3. Run sitemap.pl with an invalid directory: k$ perl misc/cronjobs/sitemap.pl --dir /nonexistent ; echo "exit=$?" => SUCCESS: "This is not a valid directory: /nonexistent" and a non-zero exit status (it was 0 before this patch) 4. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) -- You are receiving this mail because: You are watching all bug changes. You are the assignee for the bug.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|NEW |Needs Signoff Assignee|koha-bugs@lists.koha-commun |tomascohen@gmail.com |ity.org | -- You are receiving this mail because: You are the assignee for the bug. You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Blocks| |44314 Referenced Bugs: https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44314 [Bug 44314] koha-sitemap stops at the first failure (or non-enabled instance with --quiet) and doesn't report errors -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Status|Needs Signoff |Signed Off -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 David Nind <david@davidnind.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Attachment #212744|0 |1 is obsolete| | Attachment #212745|0 |1 is obsolete| | -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 --- Comment #3 from David Nind <david@davidnind.com> --- Created attachment 212750 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212750&action=edit Bug 44315: Add regression tests This patch adds tests for Koha::Sitemapper's error handling: when the target directory is not valid, or a sitemap file cannot be created, it must die instead of exiting the process with status 0. Test plan: 1. Apply patch 2. Run: $ ktd --shell k$ prove t/db_dependent/Sitemapper.t => FAIL: Tests fail! The test file stops when creating the Sitemapper with an invalid directory: Koha::Sitemapper calls exit 3. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 --- Comment #4 from David Nind <david@davidnind.com> --- Created attachment 212751 --> https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=212751&action=edit Bug 44315: Make Koha::Sitemapper die on errors instead of exiting Koha::Sitemapper (invalid 'dir') and Koha::Sitemapper::Writer (sitemap file cannot be created) printed a message to STDOUT and called exit, which ends the process with status 0. sitemap.pl then reported success although no sitemap was written, so callers like koha-sitemap could not notice the failure. This patch makes them die instead, with the reason on STDERR (including the system error when a file cannot be created), so sitemap.pl exits with a non-zero status. Test plan: 1. Apply the regression tests patch and run: $ ktd --shell k$ prove t/db_dependent/Sitemapper.t => FAIL: The test file stops early 2. Apply this patch and repeat 1 => SUCCESS: Tests pass! 3. Run sitemap.pl with an invalid directory: k$ perl misc/cronjobs/sitemap.pl --dir /nonexistent ; echo "exit=$?" => SUCCESS: "This is not a valid directory: /nonexistent" and a non-zero exit status (it was 0 before this patch) 4. Sign off :-D Assisted-by: Opus 5.5 (Anthropic) Signed-off-by: David Nind <david@davidnind.com> -- You are receiving this mail because: You are watching all bug changes.
https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=44315 Tomás Cohen Arazi (tcohen) <tomascohen@gmail.com> changed: What |Removed |Added ---------------------------------------------------------------------------- Text to go in the| |`misc/cronjobs/sitemap.pl` release notes| |now exits with an error | |when it cannot write the | |sitemap, for example when | |the target directory does | |not exist or a sitemap file | |cannot be created. | |Previously it printed a | |message and exited with | |status 0, so cron jobs and | |wrappers like | |`koha-sitemap` reported | |success even though no | |sitemap was generated. The | |message is now printed to | |STDERR and says why the | |file could not be created. -- You are receiving this mail because: You are watching all bug changes.
participants (1)
-
bugzilla-daemon@bugs.koha-community.org