Improve error messages

This commit is contained in:
Andrea Cavalli 2021-10-23 01:46:27 +02:00
parent 1ed9a7739e
commit eed9a189b5
1 changed files with 21 additions and 13 deletions

View File

@ -131,34 +131,34 @@ public final class LoadLibrary {
case LINUX: case LINUX:
switch (arch) { switch (arch) {
case AMD64: case AMD64:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_AMD64_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_AMD64_CLASS, os, arch);
break; break;
case I386: case I386:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_X86_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_X86_CLASS, os, arch);
break; break;
case AARCH64: case AARCH64:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_AARCH64_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_AARCH64_CLASS, os, arch);
break; break;
case ARMHF: case ARMHF:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_ARMHF_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_ARMHF_CLASS, os, arch);
break; break;
case S390X: case S390X:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_S390X_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_S390X_CLASS, os, arch);
break; break;
case PPC64LE: case PPC64LE:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_PPC64LE_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.LINUX_PPC64LE_CLASS, os, arch);
break; break;
} }
break; break;
case OSX: case OSX:
if (arch == Arch.AMD64) { if (arch == Arch.AMD64) {
classForResource = tryLoadLibraryVersionClass(LibraryVersion.OSX_AMD64_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.OSX_AMD64_CLASS, os, arch);
} }
break; break;
case WINDOWS: case WINDOWS:
switch (arch) { switch (arch) {
case AMD64: case AMD64:
classForResource = tryLoadLibraryVersionClass(LibraryVersion.WINDOWS_AMD64_CLASS); classForResource = tryLoadLibraryVersionClass(LibraryVersion.WINDOWS_AMD64_CLASS, os, arch);
break; break;
case I386: case I386:
break; break;
@ -166,7 +166,8 @@ public final class LoadLibrary {
break; break;
} }
if (classForResource == null) { if (classForResource == null) {
throw new CantLoadLibrary("Native libraries for platform " + os + "-" + arch + " not found!"); throw new CantLoadLibrary("Native libraries for platform " + os + "-" + arch + " not found!"
+ " Required version: " + getRequiredVersionName(os, arch));
} }
InputStream libInputStream; InputStream libInputStream;
try { try {
@ -191,7 +192,7 @@ public final class LoadLibrary {
System.load(tempFile.toFile().getAbsolutePath()); System.load(tempFile.toFile().getAbsolutePath());
} }
private static Class<?> tryLoadLibraryVersionClass(String classForResource) throws CantLoadLibrary { private static Class<?> tryLoadLibraryVersionClass(String classForResource, Os os, Arch arch) throws CantLoadLibrary {
try { try {
return Class.forName(classForResource); return Class.forName(classForResource);
} catch (ClassNotFoundException e1) { } catch (ClassNotFoundException e1) {
@ -202,7 +203,8 @@ public final class LoadLibrary {
Class<?> foundAnotherVersion = Class.forName(removeFromVersion(classForResource)); Class<?> foundAnotherVersion = Class.forName(removeFromVersion(classForResource));
throw new CantLoadLibrary("Can't load the native libraries." throw new CantLoadLibrary("Can't load the native libraries."
+ " A different version of the native libraries was found." + " A different version of the native libraries was found."
+ " Please make sure that you installed the correct one.", e1); + " Please make sure that you installed the correct one."
+ " Required version: " + getRequiredVersionName(os, arch), e1);
} catch (ClassNotFoundException e2) { } catch (ClassNotFoundException e2) {
// not found arch // not found arch
@ -211,7 +213,8 @@ public final class LoadLibrary {
Class<?> foundAnotherArch = Class.forName(removeFromArch(classForResource)); Class<?> foundAnotherArch = Class.forName(removeFromArch(classForResource));
throw new CantLoadLibrary("Can't load the native libraries." throw new CantLoadLibrary("Can't load the native libraries."
+ " A different architecture of the native libraries was found." + " A different architecture of the native libraries was found."
+ " Please make sure that you installed the correct one.", e1); + " Please make sure that you installed the correct one."
+ " Required version: " + getRequiredVersionName(os, arch), e1);
} catch (ClassNotFoundException e3) { } catch (ClassNotFoundException e3) {
// not found os // not found os
@ -220,7 +223,8 @@ public final class LoadLibrary {
Class<?> foundAnotherOs = Class.forName(removeFromOs(classForResource)); Class<?> foundAnotherOs = Class.forName(removeFromOs(classForResource));
throw new CantLoadLibrary("Can't load the native libraries." throw new CantLoadLibrary("Can't load the native libraries."
+ " A different OS of the native libraries was found." + " A different OS of the native libraries was found."
+ " Please make sure that you installed the correct one.", e1); + " Please make sure that you installed the correct one."
+ " Required version: " + getRequiredVersionName(os, arch), e1);
} catch (ClassNotFoundException e4) { } catch (ClassNotFoundException e4) {
// not found anything // not found anything
@ -232,6 +236,10 @@ public final class LoadLibrary {
} }
} }
private static String getRequiredVersionName(Os os, Arch arch) {
return LibraryVersion.IMPLEMENTATION_NAME + " " + os + " " + arch + " 4.0." + LibraryVersion.NATIVES_VERSION;
}
private static String removeFromVersion(String libraryVersionClass) { private static String removeFromVersion(String libraryVersionClass) {
return removeLastPackageParts(libraryVersionClass, 1, "AnyVersion"); return removeLastPackageParts(libraryVersionClass, 1, "AnyVersion");
} }