{"record":{"id":"76c7c660d730764d","repo":"docker/cli","slug":"parsing-config-file-s-w","errorCode":null,"errorMessage":"parsing config file (%s): %w","messagePattern":"parsing config file \\((.+?)\\): %w","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"cli/config/config.go","lineNumber":150,"sourceCode":"\nfunc load(configDir string) (*configfile.ConfigFile, error) {\n\tfilename := filepath.Join(configDir, ConfigFileName)\n\tconfigFile := configfile.New(filename)\n\n\tfile, err := os.Open(filename)\n\tif err != nil {\n\t\tif os.IsNotExist(err) {\n\t\t\t// It is OK for no configuration file to be present, in which\n\t\t\t// case we return a default struct.\n\t\t\treturn configFile, nil\n\t\t}\n\t\t// Any other error happening when failing to read the file must be returned.\n\t\treturn configFile, fmt.Errorf(\"loading config file: %w\", err)\n\t}\n\tdefer func() { _ = file.Close() }()\n\terr = configFile.LoadFromReader(file)\n\tif err != nil {\n\t\terr = fmt.Errorf(\"parsing config file (%s): %w\", filename, err)\n\t}\n\treturn configFile, err\n}\n\n// LoadDefaultConfigFile attempts to load the default config file and returns\n// a reference to the ConfigFile struct. If none is found or when failing to load\n// the configuration file, it initializes a default ConfigFile struct. If no\n// credentials-store is set in the configuration file, it attempts to discover\n// the default store to use for the current platform.\n//\n// Important: LoadDefaultConfigFile prints a warning to stderr when failing to\n// load the configuration file, but otherwise ignores errors. Consumers should\n// consider using [Load] (and [credentials.DetectDefaultStore]) to detect errors\n// when updating the configuration file, to prevent discarding a (malformed)\n// configuration file.\nfunc LoadDefaultConfigFile(stderr io.Writer) *configfile.ConfigFile {\n\tconfigFile, err := load(Dir())\n\tif err != nil {","sourceCodeStart":132,"sourceCodeEnd":168,"githubUrl":"https://github.com/docker/cli/blob/4f84911bfe8811e9b028e4b1fee8e7510be79387/cli/config/config.go#L132-L168","documentation":"Returned by `load` (config.go:148-150) when the config file was opened successfully but ConfigFile.LoadFromReader failed to JSON-decode it. The filename is interpolated. LoadFromReader decodes into the ConfigFile struct and also base64-decodes each `auths[].auth`; any JSON syntax error or base64/decode error surfaces here.","triggerScenarios":"config.Load -> LoadFromReader -> json.Decoder.Decode returns a non-EOF error, OR decodeAuth fails for a malformed `auths.<addr>.auth` base64 value. The error is wrapped as `parsing config file (<filename>): <err>`.","commonSituations":"Manual edits to `~/.docker/config.json` introduced a syntax error (trailing comma, unbalanced brace, smart quotes), a credential helper wrote a truncated/corrupt file, or an `auths` entry has a `auth` value that is not valid base64 or lacks the `username:password` colon separator (decodeAuth returns `invalid auth configuration file`).","solutions":["Validate the JSON: `python -m json.tool ~/.docker/config.json` or `cat` it and look for syntax errors.","If the error mentions decoding auth, inspect each `auths` entry and ensure `auth` is base64 of `username:password`.","Back up and regenerate the file via `docker login` (re-creates a valid config), or restore from version control/backup.","Avoid hand-editing the file; use `docker logout` / `docker login` to mutate auths."],"exampleFix":"// before — corrupt JSON (trailing comma)\n{\n  \"auths\": { \"https://index.docker.io/v1/\": { \"auth\": \"...\" }, }\n}\n// after — valid JSON\n{\n  \"auths\": { \"https://index.docker.io/v1/\": { \"auth\": \"...\" } }\n}","handlingStrategy":"try-catch","validationCode":"// Validate JSON before relying on the loader.\nvar v any\nif err := json.Unmarshal(raw, &v); err != nil {\n    return fmt.Errorf(\"config.json is not valid JSON: %w\", err)\n}","typeGuard":null,"tryCatchPattern":"cfg, err := config.Load(dir)\nif err != nil {\n    return fmt.Errorf(\"failed to parse docker config: %w\", err)\n}","preventionTips":["Never hand-edit `~/.docker/config.json`; use `docker login` / `docker logout`.","Back up config.json before bulk credential changes.","Validate JSON in CI if the file is generated from a secret template."],"tags":["config","json","parse","config-json","auth"],"backgroundTag":null,"analyzedSha":"4f84911bfe8811e9b028e4b1fee8e7510be79387","analyzedAt":"2026-08-07T12:15:29.814Z","contentChangedAt":null,"schemaVersion":2},"datasetVersion":"2026-09-15T23:17:13.987Z"}