router-for-me/CLIProxyAPI · error
auth path is empty
Error message
auth path is empty
What it means
buildAuthFromFileData in auth_files_crud.go constructs a coreauth.Auth from a file path plus optional in-memory data. An empty path is rejected with `auth path is empty` because the resulting Auth record would have no resolvable file location — every later reload/delete/save of that credential keys off the path. It is a programmer/validation guard on the management API's internal file ingestion path.
Source
Thrown at internal/api/handlers/management/auth_files_crud.go:466
id = strings.ToLower(id)
}
return id
}
func (h *Handler) registerAuthFromFile(ctx context.Context, path string, data []byte) error {
if h.authManager == nil {
return nil
}
auth, err := h.buildAuthFromFileData(path, data)
if err != nil {
return err
}
return h.upsertAuthRecord(ctx, auth)
}
func (h *Handler) buildAuthFromFileData(path string, data []byte) (*coreauth.Auth, error) {
if path == "" {
return nil, fmt.Errorf("auth path is empty")
}
if data == nil {
var err error
data, err = os.ReadFile(path)
if err != nil {
return nil, fmt.Errorf("failed to read auth file: %w", err)
}
}
metadata := make(map[string]any)
if err := json.Unmarshal(data, &metadata); err != nil {
return nil, fmt.Errorf("invalid auth file: %w", err)
}
provider, _ := metadata["type"].(string)
if provider == "" {
provider = "unknown"
}
label := provider
if email, ok := metadata["email"].(string); ok && email != "" {View on GitHub (pinned to 78f0c4079e)
Solutions
- Ensure uploaded file parts carry a real filename ending in .json (curl -F 'file=@my.json').
- Client-side, reject empty filenames before uploading.
- If invoking the SDK handler directly, always pass the absolute destination path under the configured authDir.
Example fix
// before: part with no filename
multipart.append('file', blob) // no filename -> empty name
// after
multipart.append('file', blob, 'my-codex-auth.json') Defensive patterns
Strategy: validation
Validate before calling
func validUploadName(filename string) bool {
n := strings.TrimSpace(filename)
return n != "" && strings.HasSuffix(strings.ToLower(n), ".json")
} Type guard
func isEmptyAuthPath(err error) bool {
return err != nil && strings.Contains(err.Error(), "auth path is empty")
} Prevention
- Always attach uploads with an explicit .json filename.
- When calling the SDK handler directly, pass the absolute destination path under authDir.
- Reject empty filenames in client forms before submitting.
When it happens
Trigger: Calling writeAuthFile/upsertAuthFromFile with an empty string path: upload flow produced an empty filename (multipart part with empty filename after TrimSpace+Base), or internal code passed "" when persisting an auth record derived from a file.
Common situations: Multipart upload where the file part has no filename attribute (curl -F 'file=@-;filename=' tricks or programmatic clients); clients sending the file data in a field the handler does not treat as a file, leaving the derived name empty.
Related errors
- no file uploaded
- failed to open uploaded file: %w
- failed to read uploaded file: %w
- failed to write file: %w
- invalid request body
AI-assisted analysis of router-for-me/CLIProxyAPI@78f0c4079e (2026-08-15).
Data as JSON: /api/errors/0df890ccbee850ed.
Report an issue: GitHub.