flipped-aurora/gin-vue-admin · error
ErrLogRootUnavailable
ErrLogRootUnavailable
Error message
%w: %v
What it means
ListDates reads the log root directory via an os.Root-scoped ReadDir. If reading the root itself fails (permission denied, root path removed, not a directory), the error is wrapped with ErrLogRootUnavailable using %w so callers can match with errors.Is.
Source
Thrown at server/service/system/sys_log_viewer.go:56
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
}
if !exists {
return result, nil
}
defer logRoot.Close()
entries, err := fs.ReadDir(logRoot.FS(), ".")
if err != nil {
return result, fmt.Errorf("%w: %v", ErrLogRootUnavailable, err)
}
for _, entry := range entries {
if err = ctx.Err(); err != nil {
return result, err
}
if entry.Type()&os.ModeSymlink != 0 || !entry.IsDir() || !strings.HasPrefix(entry.Name(), month+"-") {
continue
}
if validateLogDate(entry.Name()) != nil {
continue
}
count, countErr := countLogFiles(ctx, logRoot, entry.Name())
if countErr != nil {
return result, countErr
}
if count == 0 {
continue
}View on GitHub (pinned to 3136500ef3)
Solutions
- Verify the configured log root path exists and is a directory
- Fix filesystem permissions so the service user can read the directory
- Mount the log volume correctly in containerized deployments
- Handle the error in the API layer with errors.Is(err, ErrLogRootUnavailable) and return a clear 500/404
Example fix
// before
service.ListDates(ctx, month) // fails: root missing
// after
if _, err := os.Stat(logDir); err != nil {
os.MkdirAll(logDir, 0o755)
}
result, err := service.ListDates(ctx, month) Defensive patterns
Strategy: try-catch
Try / catch
try {
const dates = await listDates(month)
} catch (e) {
if (e.code === 'ErrLogRootUnavailable' || /root/i.test(e.message)) {
showError('日志目录不可访问,请检查配置与权限')
}
} Prevention
- Verify log dir config before deploying
- Alert on log-root errors in monitoring
When it happens
Trigger: Calling ListDates when the configured log directory does not exist or the process lacks read permission on it; the directory was deleted/rotated while the service runs; logRoot opened but ReadDir on '.' fails.
Common situations: Wrong GVA_CONFIG log dir path in the environment; container where the log volume is not mounted; permissions changed after log rotation scripts ran.
Related errors
AI-assisted analysis of flipped-aurora/gin-vue-admin@3136500ef3 (2026-08-31).
Data as JSON: /api/errors/60011416e38ac798.
Report an issue: GitHub.