Corruption message fixes

This commit is contained in:
crschnick 2024-09-28 17:08:51 +00:00
parent e5a8745ce1
commit 8375fbd644
3 changed files with 23 additions and 10 deletions

View file

@ -56,8 +56,8 @@ public class AppExtensionManager {
ErrorEvent.fromThrowable(t).handle();
});
} catch (Throwable t) {
throw new ExtensionException(
"Service provider initialization failed. Is the installation data corrupt?", t);
throw ExtensionException.corrupt(
"Service provider initialization failed", t);
}
}
}
@ -73,7 +73,7 @@ public class AppExtensionManager {
private void loadBaseExtension() {
var baseModule = findAndParseExtension("base", ModuleLayer.boot());
if (baseModule.isEmpty()) {
throw new ExtensionException("Missing base module. Is the installation data corrupt?");
throw ExtensionException.corrupt("Missing base module");
}
baseLayer = baseModule.get().getModule().getLayer();
@ -206,8 +206,8 @@ public class AppExtensionManager {
var ext = getExtensionFromDir(layer, dir);
if (ext.isEmpty()) {
if (AppProperties.get().isFullVersion()) {
throw new ExtensionException(
"Unable to load extension from directory " + dir + ". Is the installation corrupted?");
throw ExtensionException.corrupt(
"Unable to load extension from directory " + dir);
}
} else {
if (loadedExtensions.stream()

View file

@ -57,12 +57,12 @@ public interface DataStoreProvider {
default void validate() {
for (Class<?> storeClass : getStoreClasses()) {
if (!JacksonizedValue.class.isAssignableFrom(storeClass)) {
throw new ExtensionException(
throw ExtensionException.corrupt(
String.format("Store class %s is not a Jacksonized value", storeClass.getSimpleName()));
}
if (getUsageCategory() == null) {
throw new ExtensionException("Provider %s does not have the usage category".formatted(getId()));
throw ExtensionException.corrupt("Provider %s does not have the usage category".formatted(getId()));
}
}
}

View file

@ -1,14 +1,16 @@
package io.xpipe.app.ext;
import io.xpipe.core.util.XPipeInstallation;
public class ExtensionException extends RuntimeException {
public ExtensionException() {}
public ExtensionException(String message) {
private ExtensionException(String message) {
super(message);
}
public ExtensionException(String message, Throwable cause) {
private ExtensionException(String message, Throwable cause) {
super(message, cause);
}
@ -20,7 +22,18 @@ public class ExtensionException extends RuntimeException {
super(message, cause, enableSuppression, writableStackTrace);
}
public static ExtensionException corrupt(String message, Throwable cause) {
try {
var loc = XPipeInstallation.getCurrentInstallationBasePath();
var full = message + ".\n\n" + "Please check whether the XPipe installation data at " + loc + " is corrupted.";
return new ExtensionException(full, cause);
} catch (Throwable t) {
var full = message + ".\n\n" + "Please check whether the XPipe installation data is corrupted.";
return new ExtensionException(full, cause);
}
}
public static ExtensionException corrupt(String message) {
return new ExtensionException(message + ". Is the installation data corrupt?");
return corrupt(message, null);
}
}