{"record":{"id":"798481e1b7f5e70d","repo":"hasura/graphql-engine","slug":"creating-metadata-file-s-failed-w","errorCode":null,"errorMessage":"creating metadata file %s failed: %w","messagePattern":"creating metadata file (.+?) failed: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/internal/projectmetadata/handler.go","lineNumber":71,"sourceCode":"func (h *Handler) SetMetadataObjects(objects metadataobject.Objects) {\n\th.objects = objects\n}\n\n// WriteMetadata writes the files in the metadata folder.\nfunc (h *Handler) WriteMetadata(files map[string][]byte) error {\n\tvar op internalerrors.Op = \"projectmetadata.Handler.WriteMetadata\"\n\n\tfor name, content := range files {\n\t\tfs := afero.NewOsFs()\n\t\tif err := fs.MkdirAll(filepath.Dir(name), os.ModePerm); err != nil {\n\t\t\treturn internalerrors.E(op, err)\n\t\t}\n\n\t\terr := afero.WriteFile(fs, name, content, 0o644)\n\t\tif err != nil {\n\t\t\treturn internalerrors.E(\n\t\t\t\top,\n\t\t\t\tfmt.Errorf(\"creating metadata file %s failed: %w\", name, err),\n\t\t\t)\n\t\t}\n\t}\n\n\treturn nil\n}\n\nfunc (h *Handler) ExportMetadata() (map[string][]byte, error) {\n\tvar op internalerrors.Op = \"projectmetadata.Handler.ExportMetadata\"\n\n\tmetadataFiles := make(map[string][]byte)\n\n\tvar (\n\t\tresp io.Reader\n\t\terr  error\n\t)\n\n\tresp, err = h.v1MetadataOps.ExportMetadata()","sourceCodeStart":53,"sourceCodeEnd":89,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/internal/projectmetadata/handler.go#L53-L89","documentation":"Thrown by projectmetadata.WriteMetadata when afero.WriteFile cannot create or write one of the metadata files it is exporting to disk. The %s names the target file path and %w the underlying filesystem error (permission denied, missing parent directory, read-only filesystem, etc.).","triggerScenarios":"Calling WriteMetadata when the output directory or its parent does not exist, the process lacks write permission on the target path, the disk is full, or the filesystem is read-only (e.g. CI container, mounted volume).","commonSituations":"Running `hasura metadata export` in a directory where metadata/ cannot be created, CI pipelines running as a non-root user without write access to the workspace, a full disk, or a read-only mount.","solutions":["Check the file path in the message and create its parent directory (mkdir -p metadata) or grant write permission (chmod/chown)","Verify the filesystem is writable and not out of space (df -h)","Run the command from a directory the current user owns, especially in CI containers"],"exampleFix":"// before: output dir missing\nerr := handler.WriteMetadata(exportDir) // -> creating metadata file metadata/tables.yaml failed: open ...: no such file or directory\n\n// after: ensure dir exists first\nif err := os.MkdirAll(exportDir, 0o755); err != nil { return err }\nerr := handler.WriteMetadata(exportDir)","handlingStrategy":"validation","validationCode":"func ensureWritableDir(fs afero.Fs, dir string) error {\n\tif err := fs.MkdirAll(dir, 0o755); err != nil {\n\t\treturn err\n\t}\n\tinfo, err := fs.Stat(dir)\n\tif err != nil || !info.IsDir() {\n\t\treturn fmt.Errorf(\"%s is not a directory\", dir)\n\t}\n\tprobe := filepath.Join(dir, \".probe\")\n\tif err := afero.WriteFile(fs, probe, []byte(\"x\"), 0o644); err != nil {\n\t\treturn fmt.Errorf(\"directory %s not writable: %w\", dir, err)\n\t}\n\treturn fs.Remove(probe)\n}","typeGuard":null,"tryCatchPattern":"if err := handler.WriteMetadata(dir); err != nil {\n\tif strings.Contains(err.Error(), \"creating metadata file\") {\n\t\t// prompt user to fix permissions / free disk, then retry\n\t}\n}","preventionTips":["MkdirAll the export target before calling WriteMetadata","In CI, ensure the workspace volume is writable by the CI user","Check disk space before large metadata exports"],"tags":["go","filesystem","permissions","metadata","hasura-cli"],"backgroundTag":"file-write-permission-denied","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}