From f5c55143e9137de11e978ca07b3ddece2e9287e2 Mon Sep 17 00:00:00 2001 From: Thorarinn Sigurdsson Date: Tue, 18 Jun 2024 11:06:17 +0200 Subject: [PATCH] improvement(core): fix missing action type err msg (#6176) Before this fix, we'd erroneously list the available action kinds instead of the available action types (for the invalid action's kind). Fixes https://github.com/garden-io/garden/issues/5401. --- core/src/graph/actions.ts | 22 ++++++++++++++-------- core/test/unit/src/garden.ts | 6 +++++- 2 files changed, 19 insertions(+), 9 deletions(-) diff --git a/core/src/graph/actions.ts b/core/src/graph/actions.ts index 4550e001fd..7f58e09ffc 100644 --- a/core/src/graph/actions.ts +++ b/core/src/graph/actions.ts @@ -408,15 +408,16 @@ async function processActionConfig({ scanRoot?: string }) { const actionTypes = await garden.getActionTypes() - const definition = actionTypes[config.kind][config.type]?.spec - const compatibleTypes = [config.type, ...getActionTypeBases(definition, actionTypes[config.kind]).map((t) => t.name)] + const { kind, type } = config + const definition = actionTypes[kind][type]?.spec + const compatibleTypes = [type, ...getActionTypeBases(definition, actionTypes[kind]).map((t) => t.name)] const configPath = relative(garden.projectRoot, config.internal.configFilePath || config.internal.basePath) - if (!actionTypes[config.kind][config.type]) { + if (!actionTypes[kind][type]) { const availableKinds: ActionKind[] = [] actionKinds.forEach((actionKind) => { - if (actionTypes[actionKind][config.type]) { + if (actionTypes[actionKind][type]) { availableKinds.push(actionKind) } }) @@ -424,19 +425,24 @@ async function processActionConfig({ if (availableKinds.length > 0) { throw new ConfigurationError({ message: deline` - Unrecognized ${config.type} action of kind ${config.kind} (defined at ${configPath}). - There are no ${config.type} ${config.kind} actions, did you mean to specify a ${naturalList(availableKinds, { + Unrecognized ${type} action of kind ${kind} (defined at ${configPath}). + There are no ${type} ${kind} actions, did you mean to specify a ${naturalList(availableKinds, { trailingWord: "or a", })} action(s)? `, }) } + let availableForKind: string = (Object.keys(actionTypes[kind]) || {}).map((t) => `'${t}'`).join(", ") + if (availableForKind === "") { + availableForKind = "None" + } + throw new ConfigurationError({ message: dedent` - Unrecognized action type '${config.type}' (defined at ${configPath}). Are you missing a provider configuration? + Unrecognized action type '${type}' (kind '${kind}', defined at ${configPath}). Are you missing a provider configuration? - Currently available action types: ${Object.keys(actionTypes).join(", ")}`, + Currently available '${kind}' action types: ${availableForKind}`, }) } diff --git a/core/test/unit/src/garden.ts b/core/test/unit/src/garden.ts index acf3486280..92ecad4f4b 100644 --- a/core/test/unit/src/garden.ts +++ b/core/test/unit/src/garden.ts @@ -4312,7 +4312,11 @@ describe("Garden", () => { ]) await expectError(() => garden.resolveModules({ log: garden.log }), { - contains: ["Unrecognized action type 'invalidtype'", "Are you missing a provider configuration?"], + contains: [ + "Unrecognized action type 'invalidtype'", + "Currently available 'Build' action types: 'container', 'exec', 'test'", + "Are you missing a provider configuration?", + ], }) })