Skip to content

Commit 55bc4b0

Browse files
CopilotJusterZhu
andcommitted
Address code review: improve exception handling with specific catch blocks
Co-authored-by: JusterZhu <11714536+JusterZhu@users.noreply.github.com>
1 parent 39ac0d9 commit 55bc4b0

1 file changed

Lines changed: 18 additions & 1 deletion

File tree

src/c#/GeneralUpdate.Common/Shared/Object/ConfiginfoBuilder.cs

Lines changed: 18 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -135,9 +135,24 @@ private static ConfiginfoBuilder LoadFromConfigFile()
135135

136136
return builder;
137137
}
138+
catch (System.Text.Json.JsonException)
139+
{
140+
// Invalid JSON format, fall back to parameters
141+
return null;
142+
}
143+
catch (IOException)
144+
{
145+
// File read error, fall back to parameters
146+
return null;
147+
}
148+
catch (UnauthorizedAccessException)
149+
{
150+
// Permission denied, fall back to parameters
151+
return null;
152+
}
138153
catch
139154
{
140-
// If there's any error reading or parsing the file, return null
155+
// Any other unexpected error, fall back to parameters
141156
return null;
142157
}
143158
}
@@ -184,6 +199,8 @@ private void InitializePlatformDefaults()
184199
_skipDirectorys = new List<string>();
185200

186201
// Set default InstallPath to current program running directory
202+
// This is set here to ensure the builder has a consistent default
203+
// even though BaseConfigInfo also has this default via property initializer
187204
_installPath = AppDomain.CurrentDomain.BaseDirectory;
188205
}
189206

0 commit comments

Comments
 (0)