router-for-me/CLIProxyAPI · warning
marshal auth file: %w
Error message
marshal auth file: %w
What it means
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.
Source
Thrown at internal/api/handlers/management/auth_files_fields.go:175
return fmt.Errorf("source auth path is empty")
}
data, errRead := os.ReadFile(path)
if errRead != nil {
return errRead
}
metadata := make(map[string]any)
if len(bytes.TrimSpace(data)) > 0 {
if errUnmarshal := json.Unmarshal(data, &metadata); errUnmarshal != nil {
return fmt.Errorf("invalid auth file: %w", errUnmarshal)
}
}
if metadata == nil {
metadata = make(map[string]any)
}
metadata["disabled"] = disabled
raw, errMarshal := json.Marshal(metadata)
if errMarshal != nil {
return fmt.Errorf("marshal auth file: %w", errMarshal)
}
if errWrite := os.WriteFile(path, raw, 0o600); errWrite != nil {
return errWrite
}
return nil
}
func applyAuthDisabledState(auth *coreauth.Auth, disabled bool) {
if auth == nil {
return
}
auth.Disabled = disabled
if disabled {
auth.Status = coreauth.StatusDisabled
auth.StatusMessage = "disabled via management API"
} else {
auth.Status = coreauth.StatusActive
auth.StatusMessage = ""View on GitHub (pinned to 78f0c4079e)
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
Defensive patterns
Strategy: try-catch
Try / catch
if errMarshal != nil { // practically unreachable from JSON-derived maps
log.WithError(errMarshal).Error("marshal auth file failed; keeping original file untouched")
} Prevention
- If you fork this helper, never insert non-JSON-encodable values into the metadata map
When it happens
Trigger: 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.
Common situations: Essentially never in stock deployments; appears in modified code that inserts non-marshalable values into the metadata map before the write.
Related errors
- auth file not found
- realtime_client_secret_capacity_exhausted
- invalid_session
- failed to parse response JSON: %w
- response JSON does not contain models array
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/e7590fcb206364ad.
Report an issue: GitHub.