AlistGo/alist · warning
label name is exists
Error message
label name is exists
What it means
Returned by the CreateLabel HTTP handler when db.GetLabelByName reports a label with the same name already exists. Label names are treated as globally unique; the handler returns HTTP 401 (an unusual status choice for a duplicate-resource condition — semantically 409 would fit). The check is the only uniqueness validation before db.CreateLabel.
Source
Thrown at server/handles/label.go:55
common.ErrorResp(c, err, 400)
return
}
label, err := db.GetLabelById(uint(id))
if err != nil {
common.ErrorResp(c, err, 500, true)
return
}
common.SuccessResp(c, label)
}
func CreateLabel(c *gin.Context) {
var req model.Label
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
return
}
if db.GetLabelByName(req.Name) {
common.ErrorResp(c, errors.New("label name is exists"), 401)
return
}
if id, err := db.CreateLabel(req); err != nil {
common.ErrorWithDataResp(c, err, 500, gin.H{
"id": id,
}, true)
} else {
common.SuccessResp(c, gin.H{
"id": id,
})
}
}
func UpdateLabel(c *gin.Context) {
var req model.Label
if err := c.ShouldBind(&req); err != nil {
common.ErrorResp(c, err, 400)
returnView on GitHub (pinned to 843d9dc814)
Solutions
- Choose a different, unique label name
- If the label already exists, reuse it (fetch by name) instead of creating a duplicate
- For scripts: check existence with the get-label-by-name endpoint before POSTing
Example fix
// before
POST /api/label/create {"name": "important"} // 'important' already exists
// after
GET /api/label/name/important -> 200, reuse its id Defensive patterns
Strategy: validation
Validate before calling
// Before creating, check the name is free
if existing := db.GetLabelByName(req.Name); existing {
return fmt.Errorf("label %q already exists", req.Name)
} Try / catch
resp, err := client.R().SetBody(label).Post("/api/label/create")
if err == nil && resp.StatusCode() == 401 && strings.Contains(resp.String(), "label name is exists") {
// fetch the existing label by name and reuse its id
} Prevention
- Make label-creation scripts idempotent: lookup-by-name first, create only on miss
- Note the endpoint reports duplicates as HTTP 401 — match on the message, not a conventional 409
- Trim/normalize label names client-side to avoid near-duplicate churn
When it happens
Trigger: POST to the label-creation endpoint (/api/fs/labels or the label route group) with a body whose name equals an existing label's name.
Common situations: Re-running an import/migration script that creates labels idempotently-by-name; two admins creating the same tag; a UI retry after a timeout that actually succeeded server-side.
Related errors
- file_name must not empty
- invalid file_name
- share_id must be 1-32 characters of letters, numbers, unders
- invalid request
- invalid label ID '%s': %v
AI-assisted analysis of AlistGo/alist@843d9dc814 (2026-08-15).
Data as JSON: /api/errors/8b626c2ffca964d6.
Report an issue: GitHub.