flipped-aurora/gin-vue-admin · error
parse duration < 0
Error message
parse duration < 0
What it means
For each ClearTableDetail entry, ClearTable parses the Interval string with time.ParseDuration and rejects negative durations with errors.New("parse duration < 0"), since a negative interval would compute a future cutoff time and delete nothing (or is simply a config mistake).
Source
Thrown at server/task/clearTable.go:49
})
ClearTableDetail = append(ClearTableDetail, common.ClearDB{
TableName: "sys_timed_task_logs",
CompareField: "created_at",
Interval: "720h", // 执行日志保留 30 天
})
if db == nil {
return errors.New("db Cannot be empty")
}
for _, detail := range ClearTableDetail {
duration, err := time.ParseDuration(detail.Interval)
if err != nil {
return err
}
if duration < 0 {
return errors.New("parse duration < 0")
}
err = db.Debug().Exec(fmt.Sprintf("DELETE FROM %s WHERE %s < ?", detail.TableName, detail.CompareField), time.Now().Add(-duration)).Error
if err != nil {
return err
}
}
return nil
}
View on GitHub (pinned to 3136500ef3)
Solutions
- Edit the ClearTableDetail entry in server/task/clearTable.go and remove the '-' from Interval (e.g. "720h" for 30 days).
- Keep intervals as positive duration strings understood by time.ParseDuration ("720h", "30d" is NOT valid — use hours).
- Add a startup validation/test asserting all configured intervals parse to positive values.
- Restart/re-register the timed task after fixing the config.
Example fix
// before
{ TableName: "sys_operation_records", CompareField: "created_at", Interval: "-2160h" }
// after
{ TableName: "sys_operation_records", CompareField: "created_at", Interval: "2160h" } Defensive patterns
Strategy: validation
Validate before calling
for _, d := range ClearTableDetail {
dur, err := time.ParseDuration(d.Interval)
if err != nil || dur < 0 {
return fmt.Errorf("invalid interval for %s: %q", d.TableName, d.Interval)
}
} Try / catch
if err := ClearTable(db); err != nil {
if err.Error() == "parse duration < 0" {
logger.Error("ClearTableDetail has a negative Interval; fix config")
}
return err
} Prevention
- Keep Interval strings positive and in time.ParseDuration format (e.g. "720h").
- Add a unit test validating all ClearTableDetail intervals at build time.
- Review hand edits to ClearTableDetail for sign errors.
When it happens
Trigger: A ClearTableDetail entry in clearTable.go has Interval like "-720h" or an invalid-but-parsing-negative value, so duration < 0 when ClearTable (clearTable.go:49) runs. Note: unparseable strings fail earlier at ParseDuration itself.
Common situations: Hand-editing the task's ClearTableDetail slice and accidentally prefixing a minus sign; copy-paste mistakes between Interval and other numeric configs; code-generated details with wrong sign.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/c0a5070e88fe0db9.
Report an issue: GitHub.