{"record":{"id":"a4e009c459a69712","repo":"gofr-dev/gofr","slug":"failed-to-parse-yaml-config-file-s-w","errorCode":null,"errorMessage":"failed to parse YAML config file %s: %w","messagePattern":"failed to parse YAML config file (.+?): %w","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"error","filePath":"pkg/gofr/rbac/config.go","lineNumber":147,"sourceCode":"\n// LoadPermissions loads RBAC configuration from a JSON or YAML file.\n// The file format is automatically detected based on the file extension.\n// Supported formats: .json, .yaml, .yml.\n// Dependencies (logger, metrics, tracer) are optional and can be set after loading.\nfunc LoadPermissions(path string, logger datasource.Logger, metrics container.Metrics, tracer trace.Tracer) (*Config, error) {\n\tdata, err := os.ReadFile(path)\n\tif err != nil {\n\t\treturn nil, fmt.Errorf(\"failed to read RBAC config file %s: %w\", path, err)\n\t}\n\n\tvar config Config\n\n\t// Detect file format by extension\n\text := strings.ToLower(filepath.Ext(path))\n\tswitch ext {\n\tcase \".yaml\", \".yml\":\n\t\tif err := yaml.Unmarshal(data, &config); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse YAML config file %s: %w\", path, err)\n\t\t}\n\tcase \".json\", \"\":\n\t\tif err := json.Unmarshal(data, &config); err != nil {\n\t\t\treturn nil, fmt.Errorf(\"failed to parse JSON config file %s: %w\", path, err)\n\t\t}\n\tdefault:\n\t\treturn nil, fmt.Errorf(\"unsupported config file format: %s (supported: .json, .yaml, .yml): %w\", ext, errUnsupportedFormat)\n\t}\n\n\t// Set dependencies\n\tconfig.Logger = logger\n\tconfig.Metrics = metrics\n\tconfig.Tracer = tracer\n\n\t// Initialize mux router for pattern matching\n\t// Use StrictSlash(false) to match the application router's behavior\n\tconfig.muxRouter = mux.NewRouter().StrictSlash(false)\n","sourceCodeStart":129,"sourceCodeEnd":165,"githubUrl":"https://github.com/gofr-dev/gofr/blob/187eb24962502e91f1fee856230670958b66e89c/pkg/gofr/rbac/config.go#L129-L165","documentation":"LoadPermissions failed to parse the RBAC config file as YAML. yaml.Unmarshal rejected the file contents (or the wrapper surfaced a prior read/format failure), so the RBAC permission set could not be built and EnableRBAC aborts. The path is included so you can locate the offending file.","triggerScenarios":"Calling EnableRBAC/LoadPermissions with a .yaml or .yml config file whose contents are not valid YAML: bad indentation, tabs instead of spaces, unquoted special characters, duplicate keys, or the file extension says YAML but the content is JSON/other.","commonSituations":"Hand-edited rbac.yaml with a broken indent; template rendering produced invalid YAML; a CI step wrote an empty or partial file; someone renamed a .json config to .yaml without converting it.","solutions":["Validate the YAML file with a linter/parser (yamllint or `go run gopkg.in/yaml.v3` unmarshal) and fix syntax at the reported line.","Confirm the file at the path in the message exists and is non-empty; check for failed template rendering or truncated writes.","If the content is JSON, rename the file to .json (or remove the extension) so the JSON branch parses it.","Ensure the structs match the YAML shape (field names/tags) if unmarshalling reports type errors wrapped in this message."],"exampleFix":"// before (rbac.yaml)\nroles:\n\tadmin:\n  - users:read\n// after (spaces, not tabs)\nroles:\n  admin:\n    - users:read","handlingStrategy":"try-catch","validationCode":"data, err := os.ReadFile(path)\nif err != nil { return err }\nif strings.ToLower(filepath.Ext(path)) == \".yaml\" || strings.ToLower(filepath.Ext(path)) == \".yml\" {\n    var probe map[string]any\n    if err := yaml.Unmarshal(data, &probe); err != nil {\n        return fmt.Errorf(\"rbac yaml %s invalid: %w\", path, err)\n    }\n}","typeGuard":null,"tryCatchPattern":"config, err := rbac.LoadPermissions(path, logger, metrics, tracer)\nif err != nil {\n    var perr *yaml.TypeError\n    if errors.As(err, &perr) || strings.Contains(err.Error(), \"failed to parse YAML\") {\n        logger.Fatalf(\"fix rbac yaml %v: %v\", path, err)\n    }\n    return err\n}","preventionTips":["Lint rbac yaml files in CI with yamllint before deployment.","Avoid tabs; use spaces consistently.","Never rename a JSON config to .yaml without converting it.","Fail fast at startup and log the file path and wrapped parse error."],"tags":["go","yaml","config","rbac","parse-error"],"backgroundTag":"config-file-parse-failed","analyzedSha":"187eb24962502e91f1fee856230670958b66e89c","analyzedAt":"2026-09-01T20:34:54.554Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-08T10:18:20.063Z"}