A platform for community discussion. Free, open, simple.
UX: Show hints and errors on the workflow execution page
Régis Hanol96b2f45e2f7e
diff --git a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjsindex 14bd18e50a0..5581d7d599d 100644--- a/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs+++ b/plugins/discourse-workflows/admin/assets/javascripts/admin/components/workflows/executions/detail.gjs@@ -7,6 +7,7 @@ import didUpdate from "@ember/render-modifiers/modifiers/did-update";import { service } from "@ember/service";import { ajax } from "discourse/lib/ajax";import DButton from "discourse/ui-kit/d-button";+import DFlashMessage from "discourse/ui-kit/d-flash-message";import dConcatClass from "discourse/ui-kit/helpers/d-concat-class";import dIcon from "discourse/ui-kit/helpers/d-icon";import dLoadingSpinner from "discourse/ui-kit/helpers/d-loading-spinner";@@ -188,6 +189,21 @@ function stepSummary(step) {return String(step.error);}+// A step that continued on error succeeds, so these explain what it continued past.+function stepWarnings(step) {+ const warnings = [];+ const handledError = step.metadata?.handled_error?.message;+ if (handledError) {+ warnings.push(+ i18n("discourse_workflows.executions.handled_error", {+ message: handledError,+ })+ );+ }++ return warnings;+}+function hasNoOutput(step) {return (step.status === "success" &&@@ -286,6 +302,19 @@ export default class ExecutionDetail extends Component {return isLive(this.execution);}+ get executionError() {+ // A failing step already explains the error in its summary.+ if (this.execution.steps?.some((step) => step.error)) {+ return null;+ }++ return this.execution.error;+ }++ get executionErrorType() {+ return this.execution.status === "error" ? "error" : "warning";+ }+@actionasync initialize() {this.#progress.lastMessageId = this.execution.message_bus_last_id ?? 0;@@ -341,6 +370,14 @@ export default class ExecutionDetail extends Component {` Duration: ${formatDuration(step.started_at, step.finished_at)}${step.metadata?.js_elapsed_ms ? ` (javascript: ${step.metadata.js_elapsed_ms}ms)` : ""}`);+ stepWarnings(step).forEach((warning) => {+ lines.push(` Warning: ${warning}`);+ });++ step.metadata?.hints?.forEach((hint) => {+ lines.push(` Hint: ${hint.message}`);+ });+if (step.metadata?.conditions) {lines.push(" Conditions:");step.metadata.conditions.forEach((c) => {@@ -555,6 +592,12 @@ export default class ExecutionDetail extends Component {</div>{{/if}}+ <DFlashMessage+ class="workflows-execution-detail__error"+ @flash={{this.executionError}}+ @type={{this.executionErrorType}}+ />+<div class="workflows-execution-detail__steps">{{#each this.execution.steps as |step|}}<div@@ -627,12 +670,30 @@ export default class ExecutionDetail extends Component {{{/if}}<div class="workflows-execution-detail__step-body">+ {{#each (stepWarnings step) as |warning|}}+ <DFlashMessage+ class="workflows-execution-detail__step-warning"+ @flash={{warning}}+ @type="warning"+ />+ {{/each}}++ {{#each step.metadata.hints as |hint|}}+ <DFlashMessage+ class="workflows-execution-detail__hint"+ @flash={{hint.message}}+ @type="warning"+ />+ {{/each}}+{{#if (hasNoOutput step)}}- <div- class="alert alert-info workflows-execution-detail__no-output"- >- {{i18n "discourse_workflows.executions.no_output_data"}}- </div>+ <DFlashMessage+ class="workflows-execution-detail__no-output"+ @flash={{i18n+ "discourse_workflows.executions.no_output_data"+ }}+ @type="info"+ />{{/if}}{{#if step.metadata.conditions}}@@ -787,7 +848,7 @@ export default class ExecutionDetail extends Component {}}</div><DButton- class="btn-default btn-small"+ class="btn-default btn-small workflows-execution-detail__export"@action={{this.exportAsText}}@icon="download"@label="discourse_workflows.executions.export"diff --git a/plugins/discourse-workflows/config/locales/client.en.yml b/plugins/discourse-workflows/config/locales/client.en.ymlindex b25e3530f43..eca3ceaf35f 100644--- a/plugins/discourse-workflows/config/locales/client.en.yml+++ b/plugins/discourse-workflows/config/locales/client.en.yml@@ -1411,6 +1411,7 @@ en:output: "Output"no_output_data: "This node produced no output data, so the execution stopped and no items were passed to connected nodes. To continue the execution with an empty item, turn on Always output data in this node's Settings tab."items: "items"+ handled_error: "The node failed but the workflow continued because of its error settings: %{message}"logs: "Console"workflow_call: "Workflow call"workflow_call_called_by: "Called by"diff --git a/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb b/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rbindex 3cbd4e29caf..66a8df64ee1 100644--- a/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb+++ b/plugins/discourse-workflows/lib/discourse_workflows/executor/node_execution_context.rb@@ -87,8 +87,9 @@ module DiscourseWorkflows@condition_step_details.concat(details)end+ # Per-item nodes would otherwise repeat the same hint once per item.def add_execution_hints(hints)- @execution_hints.concat(hints.map(&:deep_stringify_keys))+ @execution_hints |= hints.map(&:deep_stringify_keys)enddef merge_metadata(metadata)diff --git a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rbindex ce224c1ac04..747371a17be 100644--- a/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb+++ b/plugins/discourse-workflows/spec/lib/discourse_workflows/executor/node_execution_context_spec.rb@@ -295,6 +295,20 @@ RSpec.describe DiscourseWorkflows::Executor::NodeExecutionContext doendend+ describe "#add_execution_hints" do+ it "keeps a repeated hint only once" do+ ctx = described_class.new(input_items: [], resolver: nil)++ ctx.add_execution_hints({ message: "Same", location: "outputPane" })+ ctx.add_execution_hints(+ { message: "Same", location: "outputPane" },+ { message: "Other", location: "outputPane" },+ )++ expect(ctx.execution_hints.map { |hint| hint["message"] }).to eq(%w[Same Other])+ end+ end+describe "#set_metadata" doit "merges execution metadata with string keys" doctx = described_class.new(input_items: [], resolver: nil)diff --git a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjsindex 1b35dc7afe9..79274502043 100644--- a/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs+++ b/plugins/discourse-workflows/test/javascripts/integration/components/workflows/executions/detail-test.gjs@@ -1,6 +1,7 @@import Service from "@ember/service";import { click, render, settled } from "@ember/test-helpers";import { module, test } from "qunit";+import sinon from "sinon";import { setupRenderingTest } from "discourse/tests/helpers/component-test";import pretender, { response } from "discourse/tests/helpers/create-pretender";import { fakeTime } from "discourse/tests/helpers/qunit-helpers";@@ -150,6 +151,102 @@ module(.hasText("{}", "the empty item remains distinguishable from no items");});+ test("renders execution hints and handled errors for any node", async function (assert) {+ this.execution = executionWithOutput([{ json: { value: 1 } }]);+ this.execution.steps[0].metadata = {+ hints: [+ { message: "First hint", location: "outputPane" },+ { message: "Second hint" },+ ],+ handled_error: {+ message: "Boom",+ name: "DiscourseWorkflows::NodeError",+ },+ };++ await render(+ <template><ExecutionDetail @execution={{this.execution}} /></template>+ );++ assert+ .dom(".workflows-execution-detail__hint.alert-warning")+ .exists({ count: 2 }, "every hint renders as a warning");+ assert+ .dom(".workflows-execution-detail__step-warning.alert-warning")+ .hasText(+ "The node failed but the workflow continued because of its error settings: Boom",+ "the error that the node continued past is explained"+ );+ });++ test("renders execution errors that no step already shows", async function (assert) {+ this.execution = {+ ...executionWithOutput([{ json: { value: 1 } }]),+ status: "error",+ error: "Workflow could not start",+ };++ await render(+ <template><ExecutionDetail @execution={{this.execution}} /></template>+ );++ assert+ .dom(".workflows-execution-detail__error.alert-error")+ .hasText("Workflow could not start");+ });++ test("does not show the execution error when a step has failed", async function (assert) {+ this.execution = {+ ...executionWithOutput([{ json: { value: 1 } }]),+ status: "error",+ error: "Boom [item 0]",+ };+ this.execution.steps[0].status = "error";+ this.execution.steps[0].error = "Boom";++ await render(+ <template><ExecutionDetail @execution={{this.execution}} /></template>+ );++ assert.dom(".workflows-execution-detail__error").doesNotExist();+ assert.dom(".workflows-execution-detail__step-summary").hasText("Boom");+ });++ test("includes hints and warnings in the text export", async function (assert) {+ this.execution = executionWithOutput([{ json: { value: 1 } }]);+ this.execution.steps[0].metadata = {+ hints: [{ message: "First hint" }],+ handled_error: { message: "Boom" },+ };+ const createObjectURL = sinon+ .stub(URL, "createObjectURL")+ .returns("blob:export");+ sinon.stub(URL, "revokeObjectURL");+ sinon.stub(HTMLAnchorElement.prototype, "click");++ try {+ await render(+ <template><ExecutionDetail @execution={{this.execution}} /></template>+ );+ await click(".workflows-execution-detail__export");++ const text = await createObjectURL.firstCall.args[0].text();++ assert.true(+ text.includes(+ " Warning: The node failed but the workflow continued because of its error settings: Boom"+ ),+ "the handled error is exported"+ );+ assert.true(+ text.includes(" Hint: First hint"),+ "the hint is exported"+ );+ } finally {+ sinon.restore();+ }+ });+test("opens workflow call child executions through the admin route", async function (assert) {this.execution = {id: 11471,