IceWhaleTech/CasaOS · error
create config failed
Error message
create config failed
What it means
Returned by CreateConfig() in pkg/utils/httper/drive.go when POST /config/create responds non-200. This call creates an rclone remote config: it sends name, a JSON-serialized parameters map, and a backend type. rclone rejects creation when the name is duplicated, the type is unknown, or a required backend field is missing/invalid. Note the code logs the response before checking err, and also silently swallows the json.Marshal error via `_`.
Source
Thrown at pkg/utils/httper/drive.go:126
logger.Info("unmount then", zap.Any("res", res.Body()))
return nil
}
func CreateConfig(data map[string]string, name, t string) error {
data["config_is_local"] = "false"
dataStr, _ := json.Marshal(data)
res, err := NewRestyClient().R().SetFormData(map[string]string{
"name": name,
"parameters": string(dataStr),
"type": t,
}).Post("/config/create")
logger.Info("when create config then", zap.Any("res", res.Body()))
if err != nil {
return err
}
if res.StatusCode() != 200 {
return fmt.Errorf("create config failed")
}
return nil
}
func GetConfigByName(name string) (map[string]string, error) {
res, err := NewRestyClient().R().SetFormData(map[string]string{
"name": name,
}).Post("/config/get")
if err != nil {
return nil, err
}
if res.StatusCode() != 200 {
return nil, fmt.Errorf("create config failed")
}
var result map[string]string
json.Unmarshal(res.Body(), &result)View on GitHub (pinned to 0d3b2f444e)
Solutions
- Call GetAllConfigName() first and skip or delete-and-recreate if the name already exists.
- Validate t against rclone's known backend list (rclone list backends / config providers endpoint) before creating.
- Check res.Body() content: rclone returns a plain-text reason that names the failing option.
- Handle the json.Marshal error instead of discarding it, so an unserializable map fails fast with a real message.
- Move the logger.Info call after the err check so transport failures are not masked by a nil-dereference style panic.
Example fix
// before
dataStr, _ := json.Marshal(data)
res, err := NewRestyClient().R().SetFormData(map[string]string{...}).Post("/config/create")
logger.Info("when create config then", zap.Any("res", res.Body()))
if err != nil {
return err
}
if res.StatusCode() != 200 {
return fmt.Errorf("create config failed")
}
// after
dataStr, err := json.Marshal(data)
if err != nil {
return fmt.Errorf("marshal config parameters: %w", err)
}
res, err := NewRestyClient().R().SetFormData(map[string]string{
"name": name,
"parameters": string(dataStr),
"type": t,
}).Post("/config/create")
if err != nil {
return err
}
if res.StatusCode() != 200 {
return fmt.Errorf("create config failed: status=%d body=%s", res.StatusCode(), res.Body())
} Defensive patterns
Strategy: validation
Validate before calling
// before CreateConfig()
names, err := httper.GetAllConfigName()
if err != nil {
return err
}
for _, existing := range names.Remotes {
if existing == name {
return fmt.Errorf("remote %q already exists", name)
}
}
// validate backend type against rclone's provider list before sending Try / catch
if err := httper.CreateConfig(params, name, backendType); err != nil {
if strings.Contains(err.Error(), "create config failed") {
// deterministic server-side rejection: fix inputs, do not retry
return fmt.Errorf("rclone rejected config %s (type %s): %w", name, backendType, err)
}
return err // transport failure: safe to retry once
} Prevention
- Always pre-check remote name uniqueness via listremotes.
- Keep a whitelist of supported backend types and validate user input against it.
- Handle the json.Marshal error; never discard it with _.
- Log the response body on failure — rclone names the exact offending option.
When it happens
Trigger: (1) A remote with the same name already exists (rclone config create on existing name fails unless update is forced), (2) t is not a valid rclone backend type string (e.g. 'onnedrive' instead of 'onedrive'), (3) parameters JSON is missing mandatory fields for the backend (client_id/secret, token), (4) the serialized parameters map is not valid rclone option syntax so rclone answers 400/500.
Common situations: Adding the same cloud drive twice from the CasaOS UI; typo'd or version-mismatched backend type after upgrading the rclone binary; OAuth token missing because the flow was never completed; parameter keys cased differently than rclone expects (rclone options are case-sensitive).
Related errors
AI-assisted analysis of IceWhaleTech/CasaOS@0d3b2f444e (2026-08-15).
Data as JSON: /api/errors/f052bf5d46aff379.
Report an issue: GitHub.