router-for-me/CLIProxyAPI · warning
metadata is nil
Error message
metadata is nil
What it means
setAuthFileMetadataValue was invoked with a nil metadata map, so there is nowhere to write the requested dotted-path field. Callers load metadata from an auth file beforehand; nil means that load step produced nothing (caller passed nil explicitly or the file was empty), and the helper treats it as an invalid-state error instead of silently allocating, leaving semantics to the caller.
Source
Thrown at internal/api/handlers/management/auth_files_fields.go:347
return nil, err
}
return value, nil
}
func rootAuthFileField(path string) string {
path = strings.TrimSpace(path)
if path == "" {
return ""
}
if idx := strings.Index(path, "."); idx >= 0 {
return strings.TrimSpace(path[:idx])
}
return path
}
func setAuthFileMetadataValue(metadata map[string]any, path string, value any) error {
if metadata == nil {
return fmt.Errorf("metadata is nil")
}
parts := strings.Split(path, ".")
current := metadata
for i, rawPart := range parts {
part := strings.TrimSpace(rawPart)
if part == "" {
return fmt.Errorf("invalid field path: %s", path)
}
if i == len(parts)-1 {
current[part] = value
return nil
}
next, ok := current[part].(map[string]any)
if !ok {
next = make(map[string]any)
current[part] = next
}
current = nextView on GitHub (pinned to 78f0c4079e)
Solutions
- Check whether the target auth file is empty (wc -c) and regenerate it if truncated
- Ensure the caller initializes metadata to an empty map when the file legitimately has no content before patching fields
- Add a guard in calling code: if metadata == nil, initialize it or return a clearer file-level error
- Retry the field PATCH after the file is valid JSON
Example fix
// before
var metadata map[string]any
setAuthFileMetadataValue(metadata, "weight", 2)
// after
metadata := map[string]any{}
if len(data) > 0 { json.Unmarshal(data, &metadata) }
setAuthFileMetadataValue(metadata, "weight", 2) Defensive patterns
Strategy: validation
Validate before calling
if metadata == nil {
metadata = map[string]any{} // or reject with a clearer file-level error
} Type guard
func hasMetadata(m map[string]any) bool { return m != nil } Prevention
- Always initialize the metadata map after reading a possibly-empty file
- Detect zero-byte auth files at startup and quarantine them
When it happens
Trigger: PATCH of an auth-file field where the source file was empty or blank so the caller's metadata map stayed nil, or where the caller skipped the load entirely; any code path reaching field-patch without a successfully parsed file backing it.
Common situations: Empty (zero-byte) auth files after a truncated save; test code invoking the setter with a nil map; refactors that reordered load-then-set logic.
Related errors
- source auth path is empty
- auth path is empty
- count must be a positive integer
- Codex live multipart boundary is missing
- Codex live multipart body requires an sdp field
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/0b7ba1756d643a7f.
Report an issue: GitHub.