hasura/graphql-engine · error

error generating codegen for action %s: %w

Error message

error generating codegen for action %s: %w

What it means

Thrown when the CLI's per-action code generation step (actionCfg.Codegen(actionName, derivePayload)) fails while iterating over the actions to generate handler stub code for. Codegen reads the framework template from the cloned codegen-assets repo, renders it, and writes the output directory; failure at any of those steps raises this with the action name included.

Source

Thrown at cli/commands/actions_codegen.go:144

	if len(o.actions) == 0 {
		actionsFileContent, err := actionCfg.GetActionsFileContent()
		if err != nil {
			return errors.E(op, fmt.Errorf("error getting actions file content: %w", err))
		}

		for _, action := range actionsFileContent.Actions {
			codegenActions = append(codegenActions, action.Name)
		}
	} else {
		codegenActions = o.actions
	}

	for _, actionName := range codegenActions {
		err = actionCfg.Codegen(actionName, derivePayload)
		if err != nil {
			return errors.E(
				op,
				fmt.Errorf("error generating codegen for action %s: %w", actionName, err),
			)
		}
	}

	o.EC.Spinner.Stop()
	o.EC.Logger.Info("Codegen files generated at " + o.EC.Config.ActionConfig.Codegen.OutputDir)

	return nil
}

View on GitHub (pinned to 724551b9ae)

Solutions

  1. Read the wrapped error — it names the underlying cause (template missing, write failed, etc.).
  2. Delete and re-clone the codegen-assets repo (remove the CLI's clone dir and rerun) so templates match your CLI version.
  3. Verify config.yaml's actions.codegen.framework and output_dir are valid and the output dir is writable.
  4. Validate the failing action's definition in actions.yaml (name, handler webhook, types).
  5. Re-run `hasura actions use-codegen` to re-select a supported framework.
Defensive patterns

Strategy: fallback

Validate before calling

test -d "$HOME/.hasura/codegen-assets" && test -w "$(yq e '.actions.codegen.output_dir' config.yaml)"

Try / catch

Catch per-action failures, log the action name from the message, refresh the codegen-assets clone, and re-run codegen for remaining actions.

Prevention

When it happens

Trigger: Running `hasura actions codegen` when the codegen-assets templates for the configured framework are missing/corrupt, the configured codegen framework in config.yaml is unknown, the output directory is not writable, or the actions.yaml definition for the named action is invalid for templating.

Common situations: Config.yaml codegen section pointing to a framework not present in the cloned assets repo (stale clone after upgrading CLI), read-only project directory in CI, or actions.yaml referencing types that no longer exist.

Related errors


AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28). Data as JSON: /api/errors/b9601a43bae9bfb8. Report an issue: GitHub.