{"record":{"id":"104fec9c0c5fc950","repo":"hasura/graphql-engine","slug":"failed-to-export-metadata-w-104fec","errorCode":null,"errorMessage":"failed to export metadata: %w","messagePattern":"failed to export metadata: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":45,"sourceCode":"\tcase cli.MetadataModeYAML:\n\t\treturn &metadataModeYAMLHandler{}\n\tdefault:\n\t\treturn &metadataModeDirectoryHandler{}\n\t}\n}\n\ntype metadataModeDirectoryHandler struct{}\n\nfunc (m *metadataModeDirectoryHandler) Export(o *MetadataExportOptions) error {\n\tvar op errors.Op = \"commands.metadataModeDirectoryHandler.Export\"\n\n\tmetadataHandler := projectmetadata.NewHandlerFromEC(o.EC)\n\tfiles, err := metadataHandler.ExportMetadata()\n\n\to.EC.Spinner.Stop()\n\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"failed to export metadata: %w\", err))\n\t}\n\n\terr = metadataHandler.WriteMetadata(files)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"cannot write metadata to project: %w\", err))\n\t}\n\n\treturn nil\n}\n\nfunc (m *metadataModeDirectoryHandler) Apply(o *MetadataApplyOptions) error {\n\tvar op errors.Op = \"commands.metadataModeDirectoryHandler.Apply\"\n\n\tmetadataHandler := projectmetadata.NewHandlerFromEC(o.EC)\n\tif !o.DryRun {\n\t\tif o.EC.Config.Version == cli.V2 {\n\t\t\t_, err := metadataHandler.V1ApplyMetadata()\n\t\t\tif err != nil {","sourceCodeStart":27,"sourceCodeEnd":63,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L27-L63","documentation":"In directory metadata mode, Export first calls projectmetadata.Handler.ExportMetadata to pull metadata from the server and write it into project files; failure of that handler is wrapped here. The wrapped error may be an API failure (auth/network) or a filesystem failure writing the metadata files into the project.","triggerScenarios":"Running `hasura metadata export` in a project when the export API call fails or when writing exported files to the metadata directory fails (read-only directory, permission denied, disk full).","commonSituations":"CI containers running as non-root users without write access to the mounted project, read-only checkouts, admin secret/endpoint misconfigurations, or disk quota exhaustion on workstations.","solutions":["Check the wrapped error: 'permission denied'/'read-only file system' means a filesystem issue; HTTP statuses mean an API issue","Fix directory permissions on the metadata/ folder or remount read-write","Verify endpoint/admin-secret if the failure is server-side","Retry after freeing disk space if ENOSPC appears in the chain"],"exampleFix":null,"handlingStrategy":"validation","validationCode":"# Shell: ensure metadata dir is writable and server reachable\ntouch metadata/.write_test && rm metadata/.write_test || { echo 'metadata dir not writable'; exit 1; }\ncurl -fsS \"$ENDPOINT/healthz\" >/dev/null || { echo 'server unreachable'; exit 1; }","typeGuard":null,"tryCatchPattern":"// Go: classify failure source\nif err := handler.ExportMetadata(); err != nil {\n  var pathErr *os.PathError\n  if errors.As(err, &pathErr) {\n    // local filesystem problem\n  } else {\n    // server/API problem\n  }\n}","preventionTips":["Run the CLI as a user with write access to the project","Health-check the server before export commands"],"tags":["metadata-export","filesystem","hasura-api"],"backgroundTag":"metadata-export-failed","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}