flipped-aurora/gin-vue-admin · warning
日志月份格式不正确
Error message
日志月份格式不正确
What it means
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.
Source
Thrown at server/service/system/sys_log_viewer.go:29
pathpkg "path"
"path/filepath"
"sort"
"strings"
"time"
"github.com/flipped-aurora/gin-vue-admin/server/global"
systemReq "github.com/flipped-aurora/gin-vue-admin/server/model/system/request"
systemRes "github.com/flipped-aurora/gin-vue-admin/server/model/system/response"
)
const (
DefaultLogChunkLines = 500
MaxLogChunkBytes = 2 * 1024 * 1024
logReadBlockSize = 64 * 1024
)
var (
ErrInvalidLogMonth = errors.New("日志月份格式不正确")
ErrInvalidLogDate = errors.New("日志日期格式不正确")
ErrInvalidLogPath = errors.New("日志文件路径不合法")
ErrLogFileNotFound = errors.New("日志文件不存在")
ErrLogFileUnreadable = errors.New("日志文件不可读取")
ErrLogRootUnavailable = errors.New("日志目录不可读取")
)
type LogViewerService struct{}
func (s *LogViewerService) ListDates(ctx context.Context, month string) (result systemRes.LogDateList, err error) {
result = systemRes.LogDateList{Month: month, Dates: make([]systemRes.LogDateItem, 0)}
if err = validateLogMonth(month); err != nil {
return result, err
}
logRoot, exists, err := openConfiguredLogRoot()
if err != nil {
return result, errView on GitHub (pinned to 3136500ef3)
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.
Example fix
// before GET /logViewer/list?month=2025-8 // ErrInvalidLogMonth // after GET /logViewer/list?month=2025-08
Defensive patterns
Strategy: validation
Validate before calling
var monthRe = regexp.MustCompile(`^\d{4}-(0[1-9]|1[0-2])$`)
if !monthRe.MatchString(month) {
return fmt.Errorf("month must be YYYY-MM, got %q", month)
} Type guard
func isValidLogMonth(s string) bool {
parsed, err := time.Parse("2006-01", s)
return err == nil && parsed.Format("2006-01") == s
} Try / catch
resp, err := client.ListDates(ctx, month)
if err != nil && errors.Is(err, ErrInvalidLogMonth) {
// fix the month format client-side and retry once with a normalized value
} Prevention
- 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.
When it happens
Trigger: 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.
Common situations: 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.
Related errors
- 日志日期格式不正确
- 参数错误:executionPlan 必须提供
- packageName 不能为空
- packageType 必须是 'package' 或 'plugin'
- packageType 和 packageInfo.template 必须保持一致
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/3af8e0ac19f531a5.
Report an issue: GitHub.