Throw a custom exception when WMSA_HOME isn't found

This commit is contained in:
Viktor Lofgren 2023-06-20 11:34:20 +02:00
parent 32a6735d03
commit 9455100907
3 changed files with 16 additions and 3 deletions

View File

@ -1,6 +1,7 @@
package nu.marginalia;
import nu.marginalia.service.ServiceHomeNotConfiguredException;
import nu.marginalia.service.descriptor.HostsFile;
import java.io.FileNotFoundException;
@ -30,12 +31,12 @@ public class WmsaHome {
var ret = Path.of(retStr);
if (!Files.isDirectory(ret)) {
throw new IllegalStateException("Could not find $WMSA_HOME, either set environment variable or ensure " + retStr + " exists");
throw new ServiceHomeNotConfiguredException("Could not find $WMSA_HOME, either set environment variable or ensure " + retStr + " exists");
}
if (!Files.isDirectory(ret.resolve("model"))) {
throw new IllegalStateException("You need to run 'run/setup.sh' to download models to run/ before this will work!");
throw new ServiceHomeNotConfiguredException("You need to run 'run/setup.sh' to download models to run/ before this will work!");
}
return ret;

View File

@ -0,0 +1,11 @@
package nu.marginalia.service;
public class ServiceHomeNotConfiguredException extends RuntimeException {
public ServiceHomeNotConfiguredException() {
super("WMSA_HOME environment variable not set");
}
public ServiceHomeNotConfiguredException(String message) {
super(message);
}
}

View File

@ -6,6 +6,7 @@ import com.google.inject.Singleton;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import lombok.SneakyThrows;
import nu.marginalia.service.ServiceHomeNotConfiguredException;
import org.mariadb.jdbc.Driver;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -60,7 +61,7 @@ public class DatabaseModule extends AbstractModule {
var ret = Path.of(retStr);
if (!Files.isDirectory(ret)) {
throw new IllegalStateException("Could not find WMSA_HOME, either set environment variable or ensure /var/lib/wmsa exists");
throw new ServiceHomeNotConfiguredException("Could not find WMSA_HOME, either set environment variable or ensure /var/lib/wmsa exists");
}
return ret;
}