Skip to content

Commit

Permalink
Merge pull request #2449 from fayer3/file-capitalization-check
Browse files Browse the repository at this point in the history
add file capitalization check when debug options are enabled
  • Loading branch information
IMS212 authored Aug 21, 2024
2 parents 51097b7 + 891fdd5 commit a640a8a
Show file tree
Hide file tree
Showing 4 changed files with 36 additions and 17 deletions.
24 changes: 15 additions & 9 deletions src/main/java/net/irisshaders/iris/Iris.java
Original file line number Diff line number Diff line change
Expand Up @@ -313,6 +313,7 @@ private static boolean loadExternalShaderpack(String name) {
} catch (Exception e) {
logger.error("Failed to load the shaderpack \"{}\"!", name);
logger.error("", e);
handleException(e);

return false;
}
Expand All @@ -325,6 +326,19 @@ private static boolean loadExternalShaderpack(String name) {
return true;
}

private static void handleException(Exception e) {
if (lastDimension != null && irisConfig.areDebugOptionsEnabled()) {
Minecraft.getInstance().setScreen(new DebugLoadFailedGridScreen(Minecraft.getInstance().screen, Component.literal(e instanceof ShaderCompileException ? "Failed to compile shaders" : "Exception"), e));
} else {
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(
ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false);
} else {
storedError = Optional.of(e);
}
}
}

private static Optional<Path> loadExternalZipShaderpack(Path shaderpackPath) throws IOException {
FileSystem zipSystem = FileSystems.newFileSystem(shaderpackPath, Iris.class.getClassLoader());
zipFileSystem = zipSystem;
Expand Down Expand Up @@ -577,15 +591,7 @@ private static WorldRenderingPipeline createPipeline(NamespacedId dimensionId) {
try {
return new IrisRenderingPipeline(programs);
} catch (Exception e) {
if (irisConfig.areDebugOptionsEnabled()) {
Minecraft.getInstance().setScreen(new DebugLoadFailedGridScreen(Minecraft.getInstance().screen, Component.literal(e instanceof ShaderCompileException ? "Failed to compile shaders" : "Exception"), e));
} else {
if (Minecraft.getInstance().player != null) {
Minecraft.getInstance().player.displayClientMessage(Component.translatable(e instanceof ShaderCompileException ? "iris.load.failure.shader" : "iris.load.failure.generic").append(Component.literal("Copy Info").withStyle(arg -> arg.withUnderlined(true).withColor(ChatFormatting.BLUE).withClickEvent(new ClickEvent(ClickEvent.Action.COPY_TO_CLIPBOARD, e.getMessage())))), false);
} else {
storedError = Optional.of(e);
}
}
handleException(e);

ShaderStorageBufferHolder.forceDeleteBuffers();
logger.error("Failed to create shader rendering pipeline, disabling shaders!", e);
Expand Down
7 changes: 2 additions & 5 deletions src/main/java/net/irisshaders/iris/shaderpack/ShaderPack.java
Original file line number Diff line number Diff line change
Expand Up @@ -16,6 +16,7 @@
import net.irisshaders.iris.gui.screen.ShaderPackScreen;
import net.irisshaders.iris.helpers.StringPair;
import net.irisshaders.iris.pathways.colorspace.ColorSpace;
import net.irisshaders.iris.shaderpack.error.RusticError;
import net.irisshaders.iris.shaderpack.include.AbsolutePackPath;
import net.irisshaders.iris.shaderpack.include.IncludeGraph;
import net.irisshaders.iris.shaderpack.include.IncludeProcessor;
Expand Down Expand Up @@ -151,11 +152,7 @@ public ShaderPack(Path root, Map<String, String> changedConfigs, ImmutableList<S
IncludeGraph graph = new IncludeGraph(root, starts.build());

if (!graph.getFailures().isEmpty()) {
graph.getFailures().forEach((path, error) -> {
Iris.logger.error("{}", error.toString());
});

throw new IOException("Failed to resolve some #include directives, see previous messages for details");
throw new IOException(String.join("\n", graph.getFailures().values().stream().map(RusticError::toString).toArray(String[]::new)));
}

this.languageMap = new LanguageMap(root.resolve("lang"));
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,9 @@
package net.irisshaders.iris.shaderpack.include;

import java.nio.file.NoSuchFileException;

public class FileIncludeException extends NoSuchFileException {
public FileIncludeException(String message) {
super(message);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,12 @@ public IncludeGraph(Path root, ImmutableList<AbsolutePackPath> startingPaths) {
String source;

try {
source = readFile(next.resolved(root));
Path p = next.resolved(root);
if (Iris.getIrisConfig().areDebugOptionsEnabled() && root.isAbsolute() && !p.toAbsolutePath().toString().equals(p.toFile().getCanonicalPath())) {
throw new FileIncludeException("'" + next.getPathString() + "' doesn't exist, did you mean '" +
root.relativize(p.toFile().getCanonicalFile().toPath()).toString().replace("\\", "/") + "'?");
}
source = readFile(p);
} catch (IOException e) {
AbsolutePackPath src = cameFrom.get(next);

Expand All @@ -90,8 +95,10 @@ public IncludeGraph(Path root, ImmutableList<AbsolutePackPath> startingPaths) {

String topLevelMessage;
String detailMessage;

if (e instanceof NoSuchFileException) {
if (e instanceof FileIncludeException) {
topLevelMessage = "failed to resolve #include directive\n" + e.getMessage();
detailMessage = "file not found";
} else if (e instanceof NoSuchFileException) {
topLevelMessage = "failed to resolve #include directive";
detailMessage = "file not found";
} else {
Expand Down

0 comments on commit a640a8a

Please sign in to comment.