hasura/graphql-engine · error
error in writing %s file: %w
Error message
error in writing %s file: %w
What it means
Create cannot write the merged actions.yaml file into the metadata directory (a.MetadataDir). os.WriteFile failed — the wrapped error names the OS-level cause (missing directory, permission denied, disk full, path is a directory).
Source
Thrown at cli/internal/metadataobject/actions/actions.go:241
break
}
}
}
var common types.Common
common.Actions = sdlFromResp.Actions
common.CustomTypes = sdlFromResp.Types
common.SetExportDefault()
// write actions.yaml
commonByt, err := yaml.Marshal(common)
if err != nil {
return errors.E(op, fmt.Errorf("error in marshalling common: %w", err))
}
err = os.WriteFile(filepath.Join(a.MetadataDir, a.Filename()), commonByt, 0o644)
if err != nil {
return errors.E(op, fmt.Errorf("error in writing %s file: %w", a.Filename(), err))
}
err = os.WriteFile(filepath.Join(a.MetadataDir, graphqlFileName), data, 0o644)
if err != nil {
return errors.E(op, fmt.Errorf("error in writing %s file: %w", graphqlFileName, err))
}
return nil
}
func (a *ActionConfig) Codegen(name string, derivePld types.DerivePayload) error {
var op errors.Op = "actions.ActionConfig.Codegen"
err := a.ensureCliExt()
defer a.cleanupCliExt()
if err != nil {
return errors.E(op, err)View on GitHub (pinned to 724551b9ae)
Solutions
- Check the wrapped error for the OS cause (ENOENT vs EACCES)
- mkdir -p the metadata directory or fix the --metadata-dir /HASURA_METADATA_DIRECTORY setting
- chmod/chown the directory so the current user can write, or run with appropriate privileges
- Free disk space or remount the volume read-write if in a container
Example fix
# before hasura actions codegen ... # metadata dir missing # after mkdir -p metadata/actions hasura actions codegen ...
Defensive patterns
Strategy: validation
Validate before calling
// Ensure the metadata dir is writable before Create
info, err := os.Stat(metadataDir)
if err != nil || !info.IsDir() {
os.MkdirAll(metadataDir, 0o755)
}
if f, err := os.CreateTemp(metadataDir, ".w"); err == nil {
f.Close()
os.Remove(f.Name())
} else {
return fmt.Errorf("metadata dir not writable: %w", err)
} Try / catch
if err := actionCfg.Create(ctx); err != nil {
if pe := new(fs.PathError); errors.As(err, &pe) {
// handle OS-level write failure (permissions, missing dir)
}
} Prevention
- Pre-create the metadata directory in setup scripts
- Run CI with a user that owns the checkout
- Avoid read-only mounts for the metadata dir
When it happens
Trigger: Running actions create/export when the metadata directory does not exist, is read-only, or the process lacks write permission; actions.yaml path occupied by a directory; no disk space.
Common situations: Running the CLI in CI as a non-root user against a checked-out repo with restrictive permissions; incorrect --metadata-dir flag pointing to a nonexistent path; Docker container with a read-only mount.
Related errors
- cannot write metadata to project: %w
- writing metadata to file: %w
- error removing migrations from project: %w
- failed to create seed file: %w
- error getting directory details: %w
AI-assisted analysis of hasura/graphql-engine@724551b9ae (2026-08-28).
Data as JSON: /api/errors/5f674f814668fc86.
Report an issue: GitHub.