flipped-aurora/gin-vue-admin · warning

日志日期格式不正确

Error message

日志日期格式不正确

What it means

ErrInvalidLogDate is returned when a `date` parameter is not a strict "YYYY-MM-DD" calendar date. validateLogDate parses with time.Parse("2006-01-02") and requires the re-formatted value to equal the input, so "2025-8-1", "2025-02-30", or "20250801" are rejected. It is used by ListFiles, ReadContent and openValidatedLogFile, also acting as the first path-safety filter on date directory names.

Source

Thrown at server/service/system/sys_log_viewer.go:30

	"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, err
	}

View on GitHub (pinned to 3136500ef3)

Solutions

  1. Send date strictly as zero-padded "YYYY-MM-DD" (e.g. "2025-08-30").
  2. Validate client-side with ^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$ and a real-calendar check.
  3. Derive the date from month values returned by the list-dates API instead of constructing manually.
  4. Trim and normalize input before sending.

Example fix

// before
GET /logViewer/files?date=2025-8-1   // ErrInvalidLogDate
// after
GET /logViewer/files?date=2025-08-01
Defensive patterns

Strategy: validation

Validate before calling

var dateRe = regexp.MustCompile(`^\d{4}-(0[1-9]|1[0-2])-(0[1-9]|[12]\d|3[01])$`)
if !dateRe.MatchString(date) {
	return fmt.Errorf("date must be YYYY-MM-DD, got %q", date)
}

Type guard

func isValidLogDate(s string) bool {
	parsed, err := time.Parse("2006-01-02", s)
	return err == nil && parsed.Format("2006-01-02") == s
}

Try / catch

files, err := client.ListFiles(ctx, date)
if err != nil && errors.Is(err, ErrInvalidLogDate) {
	// normalize the date to strict YYYY-MM-DD and retry once
}

Prevention

When it happens

Trigger: Log-viewer list-files/content calls with date="2025-8-1", "2025-02-30" (nonexistent day), "08/30/2025", "2025-08-31 extra", or any non-canonical string passed as the date segment.

Common situations: Client formatting dates without zero padding; timezone math producing invalid day values; users typing dates manually; API consumers guessing the expected format.

Related errors


AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31). Data as JSON: /api/errors/23aede31c496e77e. Report an issue: GitHub.