From 852a003fae7a1d40a8c19e786553fd3ebba04d16 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Tue, 20 May 2025 15:16:38 +0100 Subject: [PATCH 1/3] Action buttons raise an Error from the last message in the log for the Action --- webapp/src/components/labThingsComponents/actionButton.vue | 6 ++++-- 1 file changed, 4 insertions(+), 2 deletions(-) diff --git a/webapp/src/components/labThingsComponents/actionButton.vue b/webapp/src/components/labThingsComponents/actionButton.vue index 00346a75..7b49e347 100644 --- a/webapp/src/components/labThingsComponents/actionButton.vue +++ b/webapp/src/components/labThingsComponents/actionButton.vue @@ -251,7 +251,7 @@ export default { this.modalNotify(`The action '${this.submitLabel}' was cancelled.`); } } catch (error) { - this.$emit("error", error | Error("Unknown error")); + this.$emit("error", error); } finally { // Reset taskRunning and taskId this.taskRunning = false; @@ -297,7 +297,9 @@ export default { else if (result == "error") { // Pass the error string back with reject if (!this.progress) this.progress = 1; - reject(new Error(response.data.output)); + // Assume that the most recent message in the log is the error message + // and raise an Error with that message + reject(new Error(response.data.log.at(-1).message)); } // If task ends without reporting an error // (NB this includes cancellation) From 9d5e6b5334c12c436ddcc8ae89fe0729aac24528 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Tue, 20 May 2025 16:11:04 +0100 Subject: [PATCH 2/3] Default error messages if the log is empty, or the log message is empty --- .../labThingsComponents/actionButton.vue | 14 +++++++++++--- 1 file changed, 11 insertions(+), 3 deletions(-) diff --git a/webapp/src/components/labThingsComponents/actionButton.vue b/webapp/src/components/labThingsComponents/actionButton.vue index 7b49e347..fdcff837 100644 --- a/webapp/src/components/labThingsComponents/actionButton.vue +++ b/webapp/src/components/labThingsComponents/actionButton.vue @@ -297,9 +297,17 @@ export default { else if (result == "error") { // Pass the error string back with reject if (!this.progress) this.progress = 1; - // Assume that the most recent message in the log is the error message - // and raise an Error with that message - reject(new Error(response.data.log.at(-1).message)); + // Test whether the log is empty. If so, return a default message + if (response.data.log.length == 0) { + var message = "Unexpected error, please check the logs"; + } + // Otherwise assume that the most recent message in the log is the error message + // If it's the empty string, use a default message + else { + message = response.data.log.at(-1).message||"Unexpected error, please check the logs"; + } + // Raise an Error with the chosen message + reject(new Error(message)); } // If task ends without reporting an error // (NB this includes cancellation) From 67c5c747539f9606a534d8bb9c05acb9e8b020a1 Mon Sep 17 00:00:00 2001 From: Joe Knapper Date: Tue, 20 May 2025 16:20:35 +0100 Subject: [PATCH 3/3] Updated comment, test most recent log is ERROR --- .../components/labThingsComponents/actionButton.vue | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/webapp/src/components/labThingsComponents/actionButton.vue b/webapp/src/components/labThingsComponents/actionButton.vue index fdcff837..7efbbbc9 100644 --- a/webapp/src/components/labThingsComponents/actionButton.vue +++ b/webapp/src/components/labThingsComponents/actionButton.vue @@ -297,12 +297,14 @@ export default { else if (result == "error") { // Pass the error string back with reject if (!this.progress) this.progress = 1; - // Test whether the log is empty. If so, return a default message - if (response.data.log.length == 0) { + // Test whether the log is empty or the most recent message is not from an error + // If so, return a default message + if (response.data.log.length == 0 | response.data.log.at(-1).levelname != "ERROR") { var message = "Unexpected error, please check the logs"; } - // Otherwise assume that the most recent message in the log is the error message - // If it's the empty string, use a default message + // As LabThings Actions add the message from any raised exception to the log, the + // last message in the log is the message from the Exception. + //If the Exception was raised with no message, use a default. else { message = response.data.log.at(-1).message||"Unexpected error, please check the logs"; }