Skip to content

Commit b06f15d

Browse files
authored
Allow for FileNotFound. Do not error, instead return a default instance (#2739)
* Allow for FileNotFound. Do not error, instead return a default instance * add tests * update proto
1 parent 6bb0fdf commit b06f15d

File tree

2 files changed

+35
-2
lines changed

2 files changed

+35
-2
lines changed

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

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -95,8 +95,13 @@ public static ClientConfig load(LoadClientConfigOptions options) throws IOExcept
9595
if (file == null || file.isEmpty()) {
9696
file = getDefaultConfigFilePath();
9797
}
98-
ClientConfigToml.TomlClientConfig result = reader.readValue(new File(file));
99-
return new ClientConfig(ClientConfigToml.getClientProfiles(result));
98+
try {
99+
ClientConfigToml.TomlClientConfig result = reader.readValue(new File(file));
100+
return new ClientConfig(ClientConfigToml.getClientProfiles(result));
101+
} catch (FileNotFoundException e) {
102+
// File not found is ok - return default empty config
103+
return getDefaultInstance();
104+
}
100105
}
101106
}
102107

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -274,6 +274,34 @@ public void loadClientOptionsTLS() throws IOException {
274274
Assert.assertTrue(context.isClient());
275275
}
276276

277+
@Test
278+
public void loadClientConfigMissingFileReturnsDefault() throws IOException {
279+
// When config file doesn't exist, should return default empty config (not throw)
280+
ClientConfig config =
281+
ClientConfig.load(
282+
LoadClientConfigOptions.newBuilder()
283+
.setConfigFilePath("/nonexistent/path/to/temporal.toml")
284+
.build());
285+
Assert.assertNotNull(config);
286+
Assert.assertTrue(config.getProfiles().isEmpty());
287+
}
288+
289+
@Test
290+
public void loadClientConfigProfileMissingFileReturnsDefault() throws IOException {
291+
// When config file doesn't exist, ClientConfigProfile.load() should also work
292+
// and return a profile with default values (potentially overridden by env vars)
293+
ClientConfigProfile profile =
294+
ClientConfigProfile.load(
295+
LoadClientConfigProfileOptions.newBuilder()
296+
.setConfigFilePath("/nonexistent/path/to/temporal.toml")
297+
.setEnvOverrides(Collections.emptyMap())
298+
.build());
299+
Assert.assertNotNull(profile);
300+
// Default values should be null/empty since no file and no env vars
301+
Assert.assertNull(profile.getAddress());
302+
Assert.assertNull(profile.getNamespace());
303+
}
304+
277305
@Test
278306
public void parseToml() throws IOException {
279307
String toml =

0 commit comments

Comments
 (0)