From f8ce022d6cf536ddf8ab4868bded5647832e3163 Mon Sep 17 00:00:00 2001 From: Jonathan Druart Date: Thu, 14 May 2020 15:34:41 +0200 Subject: [PATCH] Bug 25504: Crash with the original error if API spec are invalid Bug 24700 put the whole spec validation into a try catch block that hides the original error raised by the JSON validator. If you don't have the patches from bug 25482 and start plack under D10 you will see a huge stacktrace with, lost in the middle: Koha::REST::V1::catch {...} ("Duplicate keys not allowed, at character offset 4789 (before "...) called at /usr/share/perl5/Try/Tiny.pm line 123 The complete output is at bug 25482 comment 11. With this patch, you will get a single line: Error while loading /etc/koha/sites/kohadev/plack.psgi: Can't load application from file "/kohadevbox/koha/api/v1/app.pl": Duplicate keys not allowed, at character offset 4789 (before "editcatalogue": "cre...") at /usr/share/perl5/Mojo/JSON.pm line 39. I am all for stacktraces, but not if the error is hidden ;) Signed-off-by: Tomas Cohen Arazi --- Koha/REST/V1.pm | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/Koha/REST/V1.pm b/Koha/REST/V1.pm index 680b52cd670..b86104e61dc 100644 --- a/Koha/REST/V1.pm +++ b/Koha/REST/V1.pm @@ -74,15 +74,14 @@ sub startup { push @{$self->routes->namespaces}, 'Koha::Plugin'; # Try to load and merge all schemas first and validate the result just once. - my $spec; - try { - $spec = $validator->bundle( + my $spec = $validator->bundle( { replace => 1, schema => $self->home->rel_file("api/v1/swagger/swagger.json") } ); + try { $self->plugin( 'Koha::REST::Plugin::PluginRoutes' => { spec => $spec, -- 2.26.2