{"record":{"id":"c0a5070e88fe0db9","repo":"flipped-aurora/gin-vue-admin","slug":"parse-duration-0","errorCode":null,"errorMessage":"parse duration < 0","messagePattern":"parse duration < 0","errorType":"exception","errorClass":null,"httpStatus":null,"severity":"error","filePath":"server/task/clearTable.go","lineNumber":49,"sourceCode":"\t})\n\n\tClearTableDetail = append(ClearTableDetail, common.ClearDB{\n\t\tTableName:    \"sys_timed_task_logs\",\n\t\tCompareField: \"created_at\",\n\t\tInterval:     \"720h\", // 执行日志保留 30 天\n\t})\n\n\tif db == nil {\n\t\treturn errors.New(\"db Cannot be empty\")\n\t}\n\n\tfor _, detail := range ClearTableDetail {\n\t\tduration, err := time.ParseDuration(detail.Interval)\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t\tif duration < 0 {\n\t\t\treturn errors.New(\"parse duration < 0\")\n\t\t}\n\t\terr = db.Debug().Exec(fmt.Sprintf(\"DELETE FROM %s WHERE %s < ?\", detail.TableName, detail.CompareField), time.Now().Add(-duration)).Error\n\t\tif err != nil {\n\t\t\treturn err\n\t\t}\n\t}\n\treturn nil\n}\n","sourceCodeStart":31,"sourceCodeEnd":58,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/task/clearTable.go#L31-L58","documentation":"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).","triggerScenarios":"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.","commonSituations":"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.","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."],"exampleFix":"// before\n{ TableName: \"sys_operation_records\", CompareField: \"created_at\", Interval: \"-2160h\" }\n// after\n{ TableName: \"sys_operation_records\", CompareField: \"created_at\", Interval: \"2160h\" }","handlingStrategy":"validation","validationCode":"for _, d := range ClearTableDetail {\n  dur, err := time.ParseDuration(d.Interval)\n  if err != nil || dur < 0 {\n    return fmt.Errorf(\"invalid interval for %s: %q\", d.TableName, d.Interval)\n  }\n}","typeGuard":null,"tryCatchPattern":"if err := ClearTable(db); err != nil {\n  if err.Error() == \"parse duration < 0\" {\n    logger.Error(\"ClearTableDetail has a negative Interval; fix config\")\n  }\n  return err\n}","preventionTips":["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."],"tags":["task","timed-task","configuration","duration","validation"],"backgroundTag":"invalid-duration-config","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}