Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -44,13 +44,16 @@ public static ClientConfig getDefaultInstance() {
private static String getDefaultConfigFilePath() {
String userDir = System.getProperty("user.home");
if (userDir == null || userDir.isEmpty()) {
throw new RuntimeException("failed getting user home directory");
return null;
}
return getDefaultConfigFilePath(userDir, System.getProperty("os.name"), System.getenv());
}

static String getDefaultConfigFilePath(
String userDir, String osName, Map<String, String> environment) {
if (userDir == null || userDir.isEmpty()) {
return null;
}
if (osName != null) {
String osNameLower = osName.toLowerCase();
if (osNameLower.contains("mac")) {
Expand All @@ -60,7 +63,7 @@ static String getDefaultConfigFilePath(
if (osNameLower.contains("win")) {
String appData = environment != null ? environment.get("APPDATA") : null;
if (appData == null || appData.isEmpty()) {
throw new RuntimeException("%APPDATA% is not defined");
return null;
}
return Paths.get(appData, "temporalio", "temporal.toml").toString();
}
Expand Down Expand Up @@ -122,6 +125,10 @@ public static ClientConfig load(LoadClientConfigOptions options) throws IOExcept
if (file == null || file.isEmpty()) {
file = getDefaultConfigFilePath();
}
// No config dir available — return default empty config
if (file == null) {
return getDefaultInstance();
}
try {
ClientConfigToml.TomlClientConfig result = reader.readValue(new File(file));
return new ClientConfig(ClientConfigToml.getClientProfiles(result));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -325,6 +325,22 @@ public void defaultConfigFilePath() {
ClientConfig.getDefaultConfigFilePath("/home/test", "Linux", Collections.emptyMap()));
}

@Test
public void loadDefaultConfigMissingHomeDir() throws IOException {
String original = System.getProperty("user.home");
try {
System.setProperty("user.home", "");
ClientConfig config =
ClientConfig.load(
LoadClientConfigOptions.newBuilder().setEnvOverrides(Collections.emptyMap()).build());
Assert.assertEquals(ClientConfig.getDefaultInstance(), config);
} finally {
if (original != null) {
System.setProperty("user.home", original);
}
}
}

@Test
public void parseToml() throws IOException {
String toml =
Expand Down
Loading