File tree Expand file tree Collapse file tree 2 files changed +35
-2
lines changed
main/java/io/temporal/envconfig
test/java/io/temporal/envconfig Expand file tree Collapse file tree 2 files changed +35
-2
lines changed Original file line number Diff line number Diff 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
Original file line number Diff line number Diff 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 =
You can’t perform that action at this time.
0 commit comments