From e44c46089841712818a062a5a1fcc6f8e0cb36db Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Mon, 30 Mar 2020 14:16:58 +0200 Subject: [PATCH] fix(cmd): better error messages in get task-result When the `get task-result` command is run for a task whose module type doesn't implement the getTaskResult handler, we now display a more helpful error message. --- garden-service/src/actions.ts | 4 ++-- garden-service/src/commands/get/get-status.ts | 6 +++--- garden-service/src/commands/get/get-task-result.ts | 10 ++++++++-- garden-service/src/tasks/get-task-result.ts | 5 +++-- garden-service/src/types/plugin/plugin.ts | 2 +- 5 files changed, 17 insertions(+), 10 deletions(-) diff --git a/garden-service/src/actions.ts b/garden-service/src/actions.ts index 21bfc9be7b..ed975d409d 100644 --- a/garden-service/src/actions.ts +++ b/garden-service/src/actions.ts @@ -495,11 +495,11 @@ export class ActionRouter implements TypeGuard { } } - async getTaskResult(params: TaskActionRouterParams): Promise { + async getTaskResult(params: TaskActionRouterParams): Promise { const { result } = await this.callTaskHandler({ params, actionType: "getTaskResult", - defaultHandler: async () => null, + defaultHandler: async () => undefined, }) result && this.validateTaskOutputs(params.task, result) return result diff --git a/garden-service/src/commands/get/get-status.ts b/garden-service/src/commands/get/get-status.ts index 5d86264f8e..580cf4a2e4 100644 --- a/garden-service/src/commands/get/get-status.ts +++ b/garden-service/src/commands/get/get-status.ts @@ -21,7 +21,7 @@ import { deline } from "../../util/string" import { EnvironmentStatusMap } from "../../types/plugin/provider/getEnvironmentStatus" import { ServiceStatus } from "../../types/service" -export type RunState = "outdated" | "succeeded" | "failed" +export type RunState = "outdated" | "succeeded" | "failed" | "not-implemented" export interface RunStatus { state: RunState @@ -129,7 +129,7 @@ async function getTaskStatuses(garden: Garden, configGraph: ConfigGraph, log: Lo ) } -function runStatus(result: R | null): RunStatus { +function runStatus(result: R | null | undefined): RunStatus { if (result) { const { startedAt, completedAt } = result return { @@ -138,6 +138,6 @@ function runStatus(result: R | null): RunStatus { state: result.success ? "succeeded" : "failed", } } else { - return { state: "outdated" } + return { state: result === null ? "outdated" : "not-implemented" } } } diff --git a/garden-service/src/commands/get/get-task-result.ts b/garden-service/src/commands/get/get-task-result.ts index 01cbb9ad29..15b8ef321a 100644 --- a/garden-service/src/commands/get/get-task-result.ts +++ b/garden-service/src/commands/get/get-task-result.ts @@ -70,10 +70,16 @@ export class GetTaskResultCommand extends Command { printHeader(headerLog, `Task result for task ${chalk.cyan(taskName)}`, "rocket") - if (result === null) { + log.info("") + + if (taskResult === null) { log.info(`Could not find results for task '${taskName}'`) } else { - log.info({ data: result }) + if (taskResult === undefined) { + log.error(`Module type ${task.module.type} for task ${taskName} does not support storing/getting task results.`) + } else { + log.info({ data: result }) + } } return { result } diff --git a/garden-service/src/tasks/get-task-result.ts b/garden-service/src/tasks/get-task-result.ts index 86a371e574..970a6fda0c 100644 --- a/garden-service/src/tasks/get-task-result.ts +++ b/garden-service/src/tasks/get-task-result.ts @@ -42,7 +42,7 @@ export class GetTaskResultTask extends BaseTask { return `getting task result '${this.task.name}' (from module '${this.task.module.name}')` } - async process(): Promise { + async process(): Promise { const log = this.log.info({ section: this.task.name, msg: "Checking result...", @@ -50,7 +50,8 @@ export class GetTaskResultTask extends BaseTask { }) const actions = await this.garden.getActionRouter() - let result: RunTaskResult | null + // The default handler (for plugins that don't implement getTaskResult) returns undefined. + let result: RunTaskResult | null | undefined try { result = await actions.getTaskResult({ task: this.task, diff --git a/garden-service/src/types/plugin/plugin.ts b/garden-service/src/types/plugin/plugin.ts index 0a7797b11f..d5dd745ac2 100644 --- a/garden-service/src/types/plugin/plugin.ts +++ b/garden-service/src/types/plugin/plugin.ts @@ -243,7 +243,7 @@ export type TaskActionParams = { export interface TaskActionOutputs { runTask: RunTaskResult - getTaskResult: RunTaskResult | null + getTaskResult: RunTaskResult | null | undefined } const taskActionDescriptions: { [P in TaskActionName]: () => PluginActionDescription } = {