Skip to content

Commit d37399c

Browse files
committed
Fix - provide default (empty) client config when default user config dir does not exist
1 parent 4557ac8 commit d37399c

File tree

2 files changed

+25
-2
lines changed

2 files changed

+25
-2
lines changed

temporal-envconfig/src/main/java/io/temporal/envconfig/ClientConfig.java

Lines changed: 9 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -44,13 +44,16 @@ public static ClientConfig getDefaultInstance() {
4444
private static String getDefaultConfigFilePath() {
4545
String userDir = System.getProperty("user.home");
4646
if (userDir == null || userDir.isEmpty()) {
47-
throw new RuntimeException("failed getting user home directory");
47+
return null;
4848
}
4949
return getDefaultConfigFilePath(userDir, System.getProperty("os.name"), System.getenv());
5050
}
5151

5252
static String getDefaultConfigFilePath(
5353
String userDir, String osName, Map<String, String> environment) {
54+
if (userDir == null || userDir.isEmpty()) {
55+
return null;
56+
}
5457
if (osName != null) {
5558
String osNameLower = osName.toLowerCase();
5659
if (osNameLower.contains("mac")) {
@@ -60,7 +63,7 @@ static String getDefaultConfigFilePath(
6063
if (osNameLower.contains("win")) {
6164
String appData = environment != null ? environment.get("APPDATA") : null;
6265
if (appData == null || appData.isEmpty()) {
63-
throw new RuntimeException("%APPDATA% is not defined");
66+
return null;
6467
}
6568
return Paths.get(appData, "temporalio", "temporal.toml").toString();
6669
}
@@ -122,6 +125,10 @@ public static ClientConfig load(LoadClientConfigOptions options) throws IOExcept
122125
if (file == null || file.isEmpty()) {
123126
file = getDefaultConfigFilePath();
124127
}
128+
// No config dir available — return default empty config
129+
if (file == null) {
130+
return getDefaultInstance();
131+
}
125132
try {
126133
ClientConfigToml.TomlClientConfig result = reader.readValue(new File(file));
127134
return new ClientConfig(ClientConfigToml.getClientProfiles(result));

temporal-envconfig/src/test/java/io/temporal/envconfig/ClientConfigProfileTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -325,6 +325,22 @@ public void defaultConfigFilePath() {
325325
ClientConfig.getDefaultConfigFilePath("/home/test", "Linux", Collections.emptyMap()));
326326
}
327327

328+
@Test
329+
public void loadDefaultConfigMissingHomeDir() throws IOException {
330+
String original = System.getProperty("user.home");
331+
try {
332+
System.setProperty("user.home", "");
333+
ClientConfig config =
334+
ClientConfig.load(
335+
LoadClientConfigOptions.newBuilder().setEnvOverrides(Collections.emptyMap()).build());
336+
Assert.assertEquals(ClientConfig.getDefaultInstance(), config);
337+
} finally {
338+
if (original != null) {
339+
System.setProperty("user.home", original);
340+
}
341+
}
342+
}
343+
328344
@Test
329345
public void parseToml() throws IOException {
330346
String toml =

0 commit comments

Comments
 (0)