Skip to content

Commit

Permalink
fix(cmd): better error messages in get task-result
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
thsig authored and edvald committed Mar 30, 2020
1 parent 5afdcb4 commit e44c460
Show file tree
Hide file tree
Showing 5 changed files with 17 additions and 10 deletions.
4 changes: 2 additions & 2 deletions garden-service/src/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -495,11 +495,11 @@ export class ActionRouter implements TypeGuard {
}
}

async getTaskResult(params: TaskActionRouterParams<GetTaskResultParams>): Promise<RunTaskResult | null> {
async getTaskResult(params: TaskActionRouterParams<GetTaskResultParams>): Promise<RunTaskResult | null | undefined> {
const { result } = await this.callTaskHandler({
params,
actionType: "getTaskResult",
defaultHandler: async () => null,
defaultHandler: async () => undefined,
})
result && this.validateTaskOutputs(params.task, result)
return result
Expand Down
6 changes: 3 additions & 3 deletions garden-service/src/commands/get/get-status.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down Expand Up @@ -129,7 +129,7 @@ async function getTaskStatuses(garden: Garden, configGraph: ConfigGraph, log: Lo
)
}

function runStatus<R extends RunResult>(result: R | null): RunStatus {
function runStatus<R extends RunResult>(result: R | null | undefined): RunStatus {
if (result) {
const { startedAt, completedAt } = result
return {
Expand All @@ -138,6 +138,6 @@ function runStatus<R extends RunResult>(result: R | null): RunStatus {
state: result.success ? "succeeded" : "failed",
}
} else {
return { state: "outdated" }
return { state: result === null ? "outdated" : "not-implemented" }
}
}
10 changes: 8 additions & 2 deletions garden-service/src/commands/get/get-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -70,10 +70,16 @@ export class GetTaskResultCommand extends Command<Args> {

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 }
Expand Down
5 changes: 3 additions & 2 deletions garden-service/src/tasks/get-task-result.ts
Original file line number Diff line number Diff line change
Expand Up @@ -42,15 +42,16 @@ export class GetTaskResultTask extends BaseTask {
return `getting task result '${this.task.name}' (from module '${this.task.module.name}')`
}

async process(): Promise<RunTaskResult | null> {
async process(): Promise<RunTaskResult | null | undefined> {
const log = this.log.info({
section: this.task.name,
msg: "Checking result...",
status: "active",
})
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,
Expand Down
2 changes: 1 addition & 1 deletion garden-service/src/types/plugin/plugin.ts
Original file line number Diff line number Diff line change
Expand Up @@ -243,7 +243,7 @@ export type TaskActionParams<T extends Module = Module> = {

export interface TaskActionOutputs {
runTask: RunTaskResult
getTaskResult: RunTaskResult | null
getTaskResult: RunTaskResult | null | undefined
}

const taskActionDescriptions: { [P in TaskActionName]: () => PluginActionDescription } = {
Expand Down

0 comments on commit e44c460

Please sign in to comment.