hasura/graphql-engine · error
error in writing codegen file: %w
Error message
error in writing codegen file: %w
What it means
Codegen received generated files from the extension but failed writing them to ActionConfig.Codegen.OutputDir. Each file from resp.Files is written with os.WriteFile; any OS-level failure aborts with this error.
Source
Thrown at cli/internal/metadataobject/actions/actions.go:294
data.CodegenConfig.URI = a.getActionsCodegenURI(data.CodegenConfig.Framework)
}
resp, err := a.cliExtensionConfig.GetActionsCodegen(data)
if err != nil {
return errors.E(
op,
fmt.Errorf("error in getting codegen for action %s: %w", data.ActionName, err),
)
}
for _, file := range resp.Files {
err = os.WriteFile(
filepath.Join(a.ActionConfig.Codegen.OutputDir, file.Name),
[]byte(file.Content),
0o644,
)
if err != nil {
return errors.E(op, fmt.Errorf("error in writing codegen file: %w", err))
}
}
return nil
}
func (a *ActionConfig) Validate() error {
return nil
}
func (a *ActionConfig) CreateFiles() error {
var (
op errors.Op = "actions.ActionConfig.CreateFiles"
common types.Common
)
data, err := yaml.Marshal(common)
if err != nil {View on GitHub (pinned to 724551b9ae)
Solutions
- Check the wrapped OS error, then create the output directory: mkdir -p <codegen.output_dir from actions.yaml>
- Ensure the directory is writable by the current user
- Verify no directory exists with the same name as a file the codegen writes
- Re-run the codegen command
Example fix
# actions.yaml # before codegen: output_dir: src/generated/ # after (create the dir, or point to an existing one) mkdir -p src/generated
Defensive patterns
Strategy: validation
Validate before calling
outDir := cfg.ActionConfig.Codegen.OutputDir
if err := os.MkdirAll(outDir, 0o755); err != nil {
return fmt.Errorf("cannot prepare codegen output dir: %w", err)
} Try / catch
if err := cfg.Codegen(name, pld); err != nil {
if pe := new(fs.PathError); errors.As(err, &pe) {
_ = os.MkdirAll(cfg.ActionConfig.Codegen.OutputDir, 0o755)
// retry codegen once
}
} Prevention
- Add codegen.output_dir creation to project bootstrap scripts
- Point output_dir at an existing, committed directory
- Ensure no directory shares a name with generated files
When it happens
Trigger: Running actions codegen when the configured output directory (from actions.yaml codegen.output_dir) does not exist or is not writable; a generated file name collides with an existing directory.
Common situations: Default output dir (./src/generated/) never created; output_dir changed in actions.yaml to a path that doesn't exist; read-only workspace or container; generated file name like `types.ts` matching an existing directory name.
Related errors
- error generating codegen for action %s: %w
- error in fetching codegen frameworks: %w
- error in writing %s file: %w
- error in getting codegen for action %s: %w
- pulling latest actions codegen files from internet failed: %
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/c8dc89a6cf3615eb.
Report an issue: GitHub.