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

  1. Confirm you are running unmodified code — if forked, audit what is inserted into the metadata map before marshal
  2. Ensure any values added to metadata are JSON-encodable basic types
  3. 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

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


AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15). Data as JSON: /api/errors/e7590fcb206364ad. Report an issue: GitHub.