{"record":{"id":"e7590fcb206364ad","repo":"router-for-me/CLIProxyAPI","slug":"marshal-auth-file-w","errorCode":null,"errorMessage":"marshal auth file: %w","messagePattern":"marshal auth file: %w","errorType":"http","errorClass":null,"httpStatus":500,"severity":"warning","filePath":"internal/api/handlers/management/auth_files_fields.go","lineNumber":175,"sourceCode":"\t\treturn fmt.Errorf(\"source auth path is empty\")\n\t}\n\tdata, errRead := os.ReadFile(path)\n\tif errRead != nil {\n\t\treturn errRead\n\t}\n\tmetadata := make(map[string]any)\n\tif len(bytes.TrimSpace(data)) > 0 {\n\t\tif errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {\n\t\t\treturn fmt.Errorf(\"invalid auth file: %w\", errUnmarshal)\n\t\t}\n\t}\n\tif metadata == nil {\n\t\tmetadata = make(map[string]any)\n\t}\n\tmetadata[\"disabled\"] = disabled\n\traw, errMarshal := json.Marshal(metadata)\n\tif errMarshal != nil {\n\t\treturn fmt.Errorf(\"marshal auth file: %w\", errMarshal)\n\t}\n\tif errWrite := os.WriteFile(path, raw, 0o600); errWrite != nil {\n\t\treturn errWrite\n\t}\n\treturn nil\n}\n\nfunc applyAuthDisabledState(auth *coreauth.Auth, disabled bool) {\n\tif auth == nil {\n\t\treturn\n\t}\n\tauth.Disabled = disabled\n\tif disabled {\n\t\tauth.Status = coreauth.StatusDisabled\n\t\tauth.StatusMessage = \"disabled via management API\"\n\t} else {\n\t\tauth.Status = coreauth.StatusActive\n\t\tauth.StatusMessage = \"\"","sourceCodeStart":157,"sourceCodeEnd":193,"githubUrl":"https://github.com/router-for-me/CLIProxyAPI/blob/78f0c4079e3e6273d65d03b5549cffc898703264/internal/api/handlers/management/auth_files_fields.go#L157-L193","documentation":"json.Marshal of the merged metadata map failed while rewriting the source auth file. Because the map was built from json.Unmarshal plus one bool field, marshal failures are nearly impossible — they would require a value of an unsupported type injected into the map, effectively only reachable if the helper's logic is copied or modified to accept externally-built maps.","triggerScenarios":"Theoretical: metadata containing a value json cannot encode (chan, func, NaN, cyclic structure) — cannot arise from the preceding Unmarshal path in normal operation; plausibly seen only in forks or tests that construct the metadata map programmatically.","commonSituations":"Essentially never in stock deployments; appears in modified code that inserts non-marshalable values into the metadata map before the write.","solutions":["Confirm you are running unmodified code — if forked, audit what is inserted into the metadata map before marshal","Ensure any values added to metadata are JSON-encodable basic types","If it recurs in stock code, capture the file content and report it as a bug with the wrapped error"],"exampleFix":null,"handlingStrategy":"try-catch","validationCode":null,"typeGuard":null,"tryCatchPattern":"if errMarshal != nil { // practically unreachable from JSON-derived maps\n    log.WithError(errMarshal).Error(\"marshal auth file failed; keeping original file untouched\")\n}","preventionTips":["If you fork this helper, never insert non-JSON-encodable values into the metadata map"],"tags":["json","edge-case","internal"],"backgroundTag":null,"analyzedSha":"78f0c4079e3e6273d65d03b5549cffc898703264","analyzedAt":"2026-08-15T12:26:37.444Z","schemaVersion":2},"datasetVersion":"2026-08-15T22:17:37.221Z"}