Error detection when opening a studio world closes #466

This commit is contained in:
Daniel Mills 2021-07-26 13:04:27 -04:00
parent f8ae842971
commit 8b599f78c0
2 changed files with 77 additions and 7 deletions

View File

@ -53,6 +53,7 @@ import org.zeroturnaround.zip.ZipUtil;
import java.awt.*; import java.awt.*;
import java.io.File; import java.io.File;
import java.io.FileReader;
import java.io.IOException; import java.io.IOException;
import java.util.Objects; import java.util.Objects;
import java.util.UUID; import java.util.UUID;
@ -72,11 +73,43 @@ public class IrisProject {
public KList<Report> scanForErrors() { public KList<Report> scanForErrors() {
KList<Report> reports = new KList<>(); KList<Report> reports = new KList<>();
IrisDataManager data = new IrisDataManager(path); IrisDataManager data = new IrisDataManager(path);
Gson g = new Gson();
MultiBurst.burst.burst(collectFiles("json").convert((i) -> () -> {
try {
new JSONObject(IO.readAll(i));
}
for (int i = 0; i < getActiveProvider().getCompound().getSize(); i++) { catch(Throwable e)
Engine e = getActiveProvider().getCompound().getEngine(i); {
IrisDimension dim = e.getDimension(); synchronized (reports)
reports.add(scanForErrors(dim)); {
reports.add(Report.builder()
.title("Invalid Json: " + i.getName())
.message(i.getAbsolutePath() + e.getMessage())
.suggestion("Correct the json")
.type(ReportType.ERROR)
.build());
}
}
}));
try {
for (int i = 0; i < getActiveProvider().getCompound().getSize(); i++) {
Engine e = getActiveProvider().getCompound().getEngine(i);
IrisDimension dim = e.getDimension();
reports.add(scanForErrors(dim));
}
}
catch(Throwable e)
{
reports.add(Report.builder()
.title("Failed to check all errors")
.message("There may be some json errors, correct those first")
.suggestion("Correct the json, or see exception below")
.type(ReportType.SEVERE_WARNING)
.build());
e.printStackTrace();
} }
return reports; return reports;
@ -157,14 +190,14 @@ public class IrisProject {
return activeProvider != null; return activeProvider != null;
} }
public KList<File> collectFiles(File f, String json) { public KList<File> collectFiles(File f, String fileExtension) {
KList<File> l = new KList<>(); KList<File> l = new KList<>();
if (f.isDirectory()) { if (f.isDirectory()) {
for (File i : f.listFiles()) { for (File i : f.listFiles()) {
l.addAll(collectFiles(i, json)); l.addAll(collectFiles(i, fileExtension));
} }
} else if (f.getName().endsWith("." + json)) { } else if (f.getName().endsWith("." + fileExtension)) {
l.add(f); l.add(f);
} }
@ -186,6 +219,41 @@ public class IrisProject {
close(); close();
} }
boolean hasError = false;
try {
KList<Report> reports = scanForErrors();
sender.sendMessage("There are " + reports.size() + " problems detected with this project. See console!");
Iris.error("===========================================================");
for(Report i : reports)
{
if(i.getType().equals(ReportType.ERROR))
{
hasError = true;
}
switch (i.getType())
{
case ERROR -> Iris.error(i.toString());
case SEVERE_WARNING -> Iris.warn(i.toString());
case WARNING -> Iris.warn(i.toString());
case NOTICE -> Iris.warn(i.toString());
}
}
Iris.error("===========================================================");
}
catch(Throwable e)
{
hasError = true;
e.printStackTrace();
}
if(hasError)
{
return;
}
IrisDimension d = IrisDataManager.loadAnyDimension(getName()); IrisDimension d = IrisDataManager.loadAnyDimension(getName());
if (d == null) { if (d == null) {
sender.sendMessage("Can't find dimension: " + getName()); sender.sendMessage("Can't find dimension: " + getName());

View File

@ -19,7 +19,9 @@
package com.volmit.iris.core.report; package com.volmit.iris.core.report;
import lombok.Builder; import lombok.Builder;
import lombok.Data;
@Data
@Builder @Builder
public class Report { public class Report {
@Builder.Default @Builder.Default