Skip to content

Commit

Permalink
Update loom native, with better error handling. (#1102)
Browse files Browse the repository at this point in the history
  • Loading branch information
modmuss50 committed Apr 20, 2024
1 parent e142cb8 commit bd00951
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 3 deletions.
2 changes: 1 addition & 1 deletion gradle/libs.versions.toml
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@ mapping-io = "0.5.1"
lorenz-tiny = "4.0.2"
mercury = "0.4.1"
kotlinx-metadata = "0.9.0"
loom-native = "0.1.1"
loom-native = "0.2.0"

# Plugins
spotless = "6.25.0"
Expand Down
14 changes: 13 additions & 1 deletion src/main/java/net/fabricmc/loom/util/ExceptionUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,15 @@
import java.util.function.BiFunction;

import org.gradle.api.Project;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.loom.nativeplatform.LoomNativePlatform;
import net.fabricmc.loom.nativeplatform.LoomNativePlatformException;

public final class ExceptionUtil {
private static final Logger LOGGER = LoggerFactory.getLogger(ExceptionUtil.class);

/**
* Creates a descriptive user-facing wrapper exception for an underlying cause.
*
Expand Down Expand Up @@ -74,7 +79,14 @@ private static void printFileLocks(String filename, Project project) {
return;
}

final List<ProcessHandle> processes = LoomNativePlatform.getProcessesWithLockOn(path);
final List<ProcessHandle> processes;

try {
processes = LoomNativePlatform.getProcessesWithLockOn(path);
} catch (LoomNativePlatformException e) {
LOGGER.error("{}, Failed to query processes holding a lock on {}", e.getMessage(), path);
return;
}

if (processes.isEmpty()) {
return;
Expand Down
13 changes: 12 additions & 1 deletion src/main/java/net/fabricmc/loom/util/ProcessUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -31,11 +31,15 @@

import org.gradle.api.Project;
import org.gradle.api.logging.LogLevel;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import net.fabricmc.loom.nativeplatform.LoomNativePlatform;
import net.fabricmc.loom.nativeplatform.LoomNativePlatformException;

public record ProcessUtil(LogLevel logLevel) {
private static final String EXPLORER_COMMAND = "C:\\Windows\\explorer.exe";
private static final Logger LOGGER = LoggerFactory.getLogger(ProcessUtil.class);

public static ProcessUtil create(Project project) {
return new ProcessUtil(project.getGradle().getStartParameter().getLogLevel());
Expand Down Expand Up @@ -92,7 +96,14 @@ private Optional<String> getWindowTitles(ProcessHandle processHandle) {
return Optional.empty();
}

List<String> titles = LoomNativePlatform.getWindowTitlesForPid(processHandle.pid());
List<String> titles;

try {
titles = LoomNativePlatform.getWindowTitlesForPid(processHandle.pid());
} catch (LoomNativePlatformException e) {
LOGGER.error("{}, Failed to query window title for pid {}", e.getMessage(), processHandle.pid());
return Optional.empty();
}

if (titles.isEmpty()) {
return Optional.empty();
Expand Down

0 comments on commit bd00951

Please sign in to comment.