Skip to content

Commit 4b1a2c4

Browse files
authored
CoreConfig: Prevent "Error invoking callback" if core.json not found (#576)
Thanks @markus-wa
1 parent 8f59fd5 commit 4b1a2c4

File tree

1 file changed

+17
-16
lines changed

1 file changed

+17
-16
lines changed

managed/CounterStrikeSharp.API/Core/CoreConfig.cs

Lines changed: 17 additions & 16 deletions
Original file line numberDiff line numberDiff line change
@@ -151,27 +151,28 @@ public void Load()
151151
_commandsRegistered = true;
152152
}
153153

154-
if (!File.Exists(_coreConfigPath))
154+
if (File.Exists(_coreConfigPath))
155155
{
156-
_logger.LogWarning(
157-
"Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.",
158-
_coreConfigPath);
159-
return;
160-
}
161-
162-
try
163-
{
164-
var data = JsonSerializer.Deserialize<CoreConfigData>(File.ReadAllText(_coreConfigPath),
165-
new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip });
166-
167-
if (data != null)
156+
try
157+
{
158+
var data = JsonSerializer.Deserialize<CoreConfigData>(File.ReadAllText(_coreConfigPath),
159+
new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip });
160+
161+
if (data != null)
162+
{
163+
_coreConfig = data;
164+
}
165+
}
166+
catch (Exception ex)
168167
{
169-
_coreConfig = data;
168+
_logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used");
170169
}
171170
}
172-
catch (Exception ex)
171+
else
173172
{
174-
_logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used");
173+
_logger.LogWarning(
174+
"Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.",
175+
_coreConfigPath);
175176
}
176177

177178
var serverCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)

0 commit comments

Comments
 (0)