{"record":{"id":"3af8e0ac19f531a5","repo":"flipped-aurora/gin-vue-admin","slug":"error-3af8e0","errorCode":null,"errorMessage":"日志月份格式不正确","messagePattern":"日志月份格式不正确","errorType":"validation","errorClass":null,"httpStatus":null,"severity":"warning","filePath":"server/service/system/sys_log_viewer.go","lineNumber":29,"sourceCode":"\tpathpkg \"path\"\n\t\"path/filepath\"\n\t\"sort\"\n\t\"strings\"\n\t\"time\"\n\n\t\"github.com/flipped-aurora/gin-vue-admin/server/global\"\n\tsystemReq \"github.com/flipped-aurora/gin-vue-admin/server/model/system/request\"\n\tsystemRes \"github.com/flipped-aurora/gin-vue-admin/server/model/system/response\"\n)\n\nconst (\n\tDefaultLogChunkLines = 500\n\tMaxLogChunkBytes     = 2 * 1024 * 1024\n\tlogReadBlockSize     = 64 * 1024\n)\n\nvar (\n\tErrInvalidLogMonth    = errors.New(\"日志月份格式不正确\")\n\tErrInvalidLogDate     = errors.New(\"日志日期格式不正确\")\n\tErrInvalidLogPath     = errors.New(\"日志文件路径不合法\")\n\tErrLogFileNotFound    = errors.New(\"日志文件不存在\")\n\tErrLogFileUnreadable  = errors.New(\"日志文件不可读取\")\n\tErrLogRootUnavailable = errors.New(\"日志目录不可读取\")\n)\n\ntype LogViewerService struct{}\n\nfunc (s *LogViewerService) ListDates(ctx context.Context, month string) (result systemRes.LogDateList, err error) {\n\tresult = systemRes.LogDateList{Month: month, Dates: make([]systemRes.LogDateItem, 0)}\n\tif err = validateLogMonth(month); err != nil {\n\t\treturn result, err\n\t}\n\n\tlogRoot, exists, err := openConfiguredLogRoot()\n\tif err != nil {\n\t\treturn result, err","sourceCodeStart":11,"sourceCodeEnd":47,"githubUrl":"https://github.com/flipped-aurora/gin-vue-admin/blob/3136500ef380842b0eb6c4daa87c3f8a47fcf9e0/server/service/system/sys_log_viewer.go#L11-L47","documentation":"ErrInvalidLogMonth is returned by the log viewer service when the `month` query parameter is not a valid calendar month in strict \"YYYY-MM\" format. validateLogMonth parses with time.Parse(\"2006-01\", ...) and additionally re-formats to confirm a canonical string, so non-canonical values like \"2025-1\", \"25-01\", or \"2025-13\" are rejected. It guards the ListDates API against malformed month paths.","triggerScenarios":"GET to the log-viewer list-dates endpoint with month=\"2025-1\", \"2025/01\", \"\", \"2025-13\", \"Jan 2025\", or any string that does not parse and round-trip exactly as 2006-01.","commonSituations":"Frontend building the month from a non-zero-padded date picker; hand-crafted curl calls; client locale formats like MM/YYYY; URL segments with stray whitespace.","solutions":["Send month as zero-padded \"YYYY-MM\" (e.g. \"2025-08\").","Validate on the client before the request: match ^\\d{4}-(0[1-9]|1[0-2])$.","If a date object is available, format with the YYYY-MM equivalent (pad month to 2 digits).","Trim whitespace from user input before sending."],"exampleFix":"// before\nGET /logViewer/list?month=2025-8   // ErrInvalidLogMonth\n// after\nGET /logViewer/list?month=2025-08","handlingStrategy":"validation","validationCode":"var monthRe = regexp.MustCompile(`^\\d{4}-(0[1-9]|1[0-2])$`)\nif !monthRe.MatchString(month) {\n\treturn fmt.Errorf(\"month must be YYYY-MM, got %q\", month)\n}","typeGuard":"func isValidLogMonth(s string) bool {\n\tparsed, err := time.Parse(\"2006-01\", s)\n\treturn err == nil && parsed.Format(\"2006-01\") == s\n}","tryCatchPattern":"resp, err := client.ListDates(ctx, month)\nif err != nil && errors.Is(err, ErrInvalidLogMonth) {\n\t// fix the month format client-side and retry once with a normalized value\n}","preventionTips":["Always zero-pad the month component (08, not 8).","Use a date formatter producing YYYY-MM, never locale formats.","Trim whitespace from user input before sending.","Feed months from the server's own API responses when possible."],"tags":["go","validation","log-viewer"],"backgroundTag":"invalid-date-format","analyzedSha":"3136500ef380842b0eb6c4daa87c3f8a47fcf9e0","analyzedAt":"2026-08-31T13:50:02.721Z","schemaVersion":2},"datasetVersion":"2026-08-31T19:17:28.585Z"}