{"record":{"id":"6471f26aee1b02e4","repo":"hasura/graphql-engine","slug":"reading-metadata-file-w","errorCode":null,"errorMessage":"reading metadata file: %w","messagePattern":"reading metadata file: %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/commands/metadata_handlers.go","lineNumber":354,"sourceCode":"\n\terr = os.WriteFile(o.EC.MetadataFile, metadataBytes, os.ModePerm)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"writing metadata to file: %w\", err))\n\t}\n\n\treturn nil\n}\n\nfunc apply(o *MetadataApplyOptions, mode cli.MetadataMode) error {\n\tvar (\n\t\top                 errors.Op = \"commands.apply\"\n\t\tlocalMetadataBytes []byte\n\t\terr                error\n\t)\n\n\tlocalMetadataBytes, err = os.ReadFile(o.EC.MetadataFile)\n\tif err != nil {\n\t\treturn errors.E(op, fmt.Errorf(\"reading metadata file: %w\", err))\n\t}\n\n\tif o.DryRun {\n\t\tif len(o.rawOutput) == 0 {\n\t\t\to.rawOutput = string(rawOutputFormatJSON)\n\t\t}\n\n\t\terr := writeByOutputFormat(o.EC.Stdout, localMetadataBytes, rawOutputFormat(o.rawOutput))\n\t\tif err != nil {\n\t\t\treturn errors.E(op, fmt.Errorf(\"displaying metadata failed: %w\", err))\n\t\t}\n\n\t\treturn nil\n\t}\n\n\tif mode == cli.MetadataModeYAML {\n\t\tlocalMetadataBytes, err = metadatautil.YAMLToJSON(localMetadataBytes)\n\t\tif err != nil {","sourceCodeStart":336,"sourceCodeEnd":372,"githubUrl":"https://github.com/hasura/graphql-engine/blob/724551b9ae87845594ef0408cff0e50eb6c90dc5/cli/commands/metadata_handlers.go#L336-L372","documentation":"The `metadata apply` command begins by reading the local metadata file (o.EC.MetadataFile) with os.ReadFile. This error means the local file could not be read — it does not exist, is not readable, or the configured path is wrong. It is purely a local filesystem error, before any server interaction.","triggerScenarios":"Running `metadata apply` when the configured metadata file does not exist at the resolved path, has no read permission, or the path points to a directory.","commonSituations":"Fresh clone where metadata file is not committed or named differently than config expects; config specifying an absolute path valid on another machine; running the CLI from the wrong working directory so a relative path does not resolve; file permissions locked down (chmod 000) or owned by another user.","solutions":["Confirm the metadata file path in your config and verify the file exists at that exact path (ls it from the CLI's working directory)","If the file is missing, run `metadata export` to generate it or restore it from version control","Fix read permissions (chmod +r) if the file exists but is unreadable","Run the CLI from the project root so relative metadata file paths resolve correctly"],"exampleFix":"# before\nhasura metadata apply  # reading metadata file: ... no such file or directory\n# after\nls metadata.json  # confirm location, fix config path, then:\nhasura metadata apply","handlingStrategy":"validation","validationCode":"if _, err := os.Stat(ec.MetadataFile); err != nil {\n  if os.IsNotExist(err) {\n    return errors.New(\"metadata file missing — run `metadata export` first\")\n  }\n  return fmt.Errorf(\"metadata file unreadable: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"if err := apply(o, mode); err != nil {\n  if strings.Contains(err.Error(), \"reading metadata file\") {\n    // create or fix the metadata file path, then retry\n  }\n}","preventionTips":["Always run `metadata export` once before `metadata apply` in new projects","Commit the metadata file to version control","Run the CLI from the project root so relative paths resolve"],"tags":["metadata","apply","filesystem","file-not-found","cli","go"],"backgroundTag":"file-not-found","analyzedSha":"724551b9ae87845594ef0408cff0e50eb6c90dc5","analyzedAt":"2026-08-28T07:32:55.105Z","schemaVersion":2},"datasetVersion":"2026-08-28T11:17:15.048Z"}