From 903f7dfbdfb7fdc67423b21c84df61ab557f5a57 Mon Sep 17 00:00:00 2001 From: Lee Wexler Date: Fri, 13 Sep 2024 14:09:17 -0400 Subject: [PATCH] Standardize LogView exception handling (#403) --- .../cluster/LogViewerAdminController.groovy | 18 ++++++++---------- 1 file changed, 8 insertions(+), 10 deletions(-) diff --git a/grails-app/controllers/io/xh/hoist/admin/cluster/LogViewerAdminController.groovy b/grails-app/controllers/io/xh/hoist/admin/cluster/LogViewerAdminController.groovy index 38b0fc8d..0b787a80 100644 --- a/grails-app/controllers/io/xh/hoist/admin/cluster/LogViewerAdminController.groovy +++ b/grails-app/controllers/io/xh/hoist/admin/cluster/LogViewerAdminController.groovy @@ -12,6 +12,7 @@ import io.xh.hoist.BaseController import io.xh.hoist.cluster.ClusterRequest import io.xh.hoist.configuration.LogbackConfig import io.xh.hoist.security.Access +import io.xh.hoist.exception.RoutineRuntimeException import static io.xh.hoist.util.Utils.getAppContext @@ -65,15 +66,12 @@ class LogViewerAdminController extends BaseController { Boolean caseSensitive def doCall() { - if (!availableFiles[filename]) throwUnavailable() - - // Catch any exceptions and render clean failure - the admin client auto-polls for log file - // updates, and we don't want to spam the logs with a repeated stacktrace. + if (!availableFiles[filename]) throwUnavailable(filename) try { def content = appContext.logReaderService.readFile(filename, startLine, maxLines, pattern, caseSensitive) return [success: true, filename: filename, content: content] - } catch (Exception e) { - return [success: false, filename: filename, content: [], exception: e.message] + } catch (FileNotFoundException ignored) { + throwUnavailable(filename) } } } @@ -99,7 +97,7 @@ class LogViewerAdminController extends BaseController { String filename File doCall() { - if (!availableFiles[filename]) throwUnavailable() + if (!availableFiles[filename]) throwUnavailable(filename) return appContext.logReaderService.get(filename) } } @@ -122,7 +120,7 @@ class LogViewerAdminController extends BaseController { filenames.each { filename -> def toDelete = available[filename] - if (!toDelete) throwUnavailable() + if (!toDelete) throwUnavailable(filename) def deleted = toDelete.delete() if (!deleted) logWarn("Failed to delete log: '$filename'.") @@ -167,7 +165,7 @@ class LogViewerAdminController extends BaseController { } } - static void throwUnavailable() { - throw new RuntimeException('Filename not valid or available') + static void throwUnavailable(String filename) { + throw new RoutineRuntimeException("Filename not valid or available: $filename") } }