Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

improvement(core): fix missing action type err msg #6176

Merged
merged 1 commit into from
Jun 18, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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) => {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'd find k as variable name slightly less confusion here, as it would be easier to distinguish from the new kind variable name in the top level

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?",
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

There is not a good page in the docs that introduces the concept of providers. The closest would probably be https://docs.garden.io/reference/project-config … should we still help the user a little bit here and ask them to have a look at the docs?

Can we find the provider names that provide the referenced action type and list them as well?

],
})
})

Expand Down