Skip to content

Commit

Permalink
improvement(core): fix missing action type err msg (#6176)
Browse files Browse the repository at this point in the history
Before this fix, we'd erroneously list the available action kinds
instead of the available action types (for the invalid action's kind).

Fixes #5401.
  • Loading branch information
thsig authored Jun 18, 2024
1 parent d02fa1b commit f5c5514
Show file tree
Hide file tree
Showing 2 changed files with 19 additions and 9 deletions.
22 changes: 14 additions & 8 deletions core/src/graph/actions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -408,35 +408,41 @@ 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)
}
})

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}`,
})
}

Expand Down
6 changes: 5 additions & 1 deletion core/test/unit/src/garden.ts
Original file line number Diff line number Diff line change
Expand Up @@ -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?",
],
})
})

Expand Down

0 comments on commit f5c5514

Please sign in to comment.