Improved Logging
This commit is contained in:
@@ -141,8 +141,11 @@ func BuildNative(p *project.Project, progress func(string)) (BuildResult, error)
|
||||
|
||||
report := ValidateProject(p)
|
||||
if report.HasErrors() {
|
||||
first := report.Diagnostics[0]
|
||||
return BuildResult{}, fmt.Errorf("topdata validation failed with %d error(s): %s: %s", report.ErrorCount(), first.Path, first.Message)
|
||||
summary := report.SummaryLines(3)
|
||||
if len(summary) > 0 {
|
||||
return BuildResult{}, fmt.Errorf("topdata validation failed with %d error(s): %s", report.ErrorCount(), summary[0])
|
||||
}
|
||||
return BuildResult{}, fmt.Errorf("topdata validation failed with %d error(s)", report.ErrorCount())
|
||||
}
|
||||
return buildNativeUnchecked(p, progress)
|
||||
}
|
||||
@@ -269,8 +272,14 @@ func buildNativeUnchecked(p *project.Project, progress func(string)) (BuildResul
|
||||
globalKeyToID[key] = rowID
|
||||
}
|
||||
|
||||
groupTotals := nativeCompileGroupTotals(collected)
|
||||
currentGroup := ""
|
||||
for _, dataset := range collected {
|
||||
progress(fmt.Sprintf("Compiling %s -> %s", dataset.Dataset.Name, dataset.Dataset.OutputName))
|
||||
group := nativeCompileGroup(dataset.Dataset.Name)
|
||||
if group != currentGroup {
|
||||
currentGroup = group
|
||||
progress(fmt.Sprintf("Compiling %s datasets (%d tables)...", group, groupTotals[group]))
|
||||
}
|
||||
compiled, err := resolveNativeDataset(dataset, globalKeyToID, globalRowByKey, tableRegistry, compiler)
|
||||
if err != nil {
|
||||
return BuildResult{}, err
|
||||
@@ -298,6 +307,27 @@ func buildNativeUnchecked(p *project.Project, progress func(string)) (BuildResul
|
||||
}, nil
|
||||
}
|
||||
|
||||
func nativeCompileGroup(datasetName string) string {
|
||||
head, _, ok := strings.Cut(datasetName, "/")
|
||||
if !ok {
|
||||
return datasetName
|
||||
}
|
||||
switch head {
|
||||
case "itemprops", "racialtypes", "damagetypes", "parts", "classes":
|
||||
return head
|
||||
default:
|
||||
return head
|
||||
}
|
||||
}
|
||||
|
||||
func nativeCompileGroupTotals(collected []nativeCollectedDataset) map[string]int {
|
||||
totals := make(map[string]int)
|
||||
for _, dataset := range collected {
|
||||
totals[nativeCompileGroup(dataset.Dataset.Name)]++
|
||||
}
|
||||
return totals
|
||||
}
|
||||
|
||||
func discoverNativeDatasets(dataDir string) ([]nativeDataset, error) {
|
||||
var datasets []nativeDataset
|
||||
err := filepath.WalkDir(dataDir, func(path string, d fs.DirEntry, err error) error {
|
||||
|
||||
@@ -36,6 +36,39 @@ type ValidationReport struct {
|
||||
Diagnostics []Diagnostic
|
||||
}
|
||||
|
||||
func (r ValidationReport) SummaryLines(maxPaths int) []string {
|
||||
type key struct {
|
||||
severity Severity
|
||||
message string
|
||||
}
|
||||
groups := map[key][]string{}
|
||||
order := make([]key, 0)
|
||||
for _, diagnostic := range r.Diagnostics {
|
||||
k := key{severity: diagnostic.Severity, message: diagnostic.Message}
|
||||
if _, ok := groups[k]; !ok {
|
||||
order = append(order, k)
|
||||
}
|
||||
groups[k] = append(groups[k], diagnostic.Path)
|
||||
}
|
||||
slices.SortFunc(order, func(a, b key) int {
|
||||
if a.severity != b.severity {
|
||||
if a.severity == SeverityError {
|
||||
return -1
|
||||
}
|
||||
return 1
|
||||
}
|
||||
return strings.Compare(a.message, b.message)
|
||||
})
|
||||
lines := make([]string, 0, len(order))
|
||||
for _, k := range order {
|
||||
paths := append([]string(nil), groups[k]...)
|
||||
slices.Sort(paths)
|
||||
paths = slices.Compact(paths)
|
||||
lines = append(lines, formatDiagnosticSummaryLine(string(k.severity), k.message, paths, maxPaths))
|
||||
}
|
||||
return lines
|
||||
}
|
||||
|
||||
func (r ValidationReport) HasErrors() bool {
|
||||
for _, diagnostic := range r.Diagnostics {
|
||||
if diagnostic.Severity == SeverityError {
|
||||
@@ -65,6 +98,24 @@ func (r ValidationReport) WarningCount() int {
|
||||
return count
|
||||
}
|
||||
|
||||
func formatDiagnosticSummaryLine(prefix, message string, paths []string, maxPaths int) string {
|
||||
if len(paths) == 0 {
|
||||
return fmt.Sprintf("%s: %s", prefix, message)
|
||||
}
|
||||
if maxPaths <= 0 {
|
||||
maxPaths = 3
|
||||
}
|
||||
display := paths
|
||||
if len(display) > maxPaths {
|
||||
display = display[:maxPaths]
|
||||
}
|
||||
location := strings.Join(display, ", ")
|
||||
if len(paths) > len(display) {
|
||||
location += fmt.Sprintf(", and %d more", len(paths)-len(display))
|
||||
}
|
||||
return fmt.Sprintf("%s: %s [%s]", prefix, message, location)
|
||||
}
|
||||
|
||||
type BuildResult struct {
|
||||
Mode string
|
||||
Output2DADir string
|
||||
|
||||
Reference in New Issue
Block a user