From 2ce8321178cd68b235aacca6d08483c5b7ee8a81 Mon Sep 17 00:00:00 2001 From: codeboyzhou Date: Tue, 5 Jan 2021 02:56:03 +0800 Subject: [PATCH] chore: give more friendly exception info while create driver (#181) --- .../java/com/microsoft/playwright/impl/DriverJar.java | 6 +++++- .../java/com/microsoft/playwright/impl/Driver.java | 10 +++++++--- 2 files changed, 12 insertions(+), 4 deletions(-) diff --git a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java index dd676fd5..50dcbc86 100644 --- a/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java +++ b/driver-bundle/src/main/java/com/microsoft/playwright/impl/DriverJar.java @@ -34,7 +34,11 @@ public class DriverJar extends Driver { } private void installBrowsers() throws IOException, InterruptedException { - Path driver = driverTempDir.resolve("playwright-cli"); + String cliFileName = super.cliFileName(); + Path driver = driverTempDir.resolve(cliFileName); + if (!Files.exists(driver)) { + throw new RuntimeException("Failed to find playwright-cli"); + } ProcessBuilder pb = new ProcessBuilder(driver.toString(), "install"); pb.redirectError(ProcessBuilder.Redirect.INHERIT); pb.redirectOutput(ProcessBuilder.Redirect.INHERIT); diff --git a/driver/src/main/java/com/microsoft/playwright/impl/Driver.java b/driver/src/main/java/com/microsoft/playwright/impl/Driver.java index 8a6211bd..3eebd491 100644 --- a/driver/src/main/java/com/microsoft/playwright/impl/Driver.java +++ b/driver/src/main/java/com/microsoft/playwright/impl/Driver.java @@ -43,14 +43,18 @@ public abstract class Driver { try { instance = createDriver(); } catch (Exception exception) { - throw new RuntimeException("Failed to find playwright-cli", exception); + throw new RuntimeException("Failed to create driver", exception); } } - String name = System.getProperty("os.name").toLowerCase().contains("windows") ? - "playwright-cli.exe" : "playwright-cli"; + String name = instance.cliFileName(); return instance.driverDir().resolve(name); } + protected String cliFileName() { + return System.getProperty("os.name").toLowerCase().contains("windows") ? + "playwright-cli.exe" : "playwright-cli"; + } + private static Driver createDriver() throws Exception { String pathFromProperty = System.getProperty("playwright.cli.dir"); if (pathFromProperty != null) {