Skip to content

Commit

Permalink
CoreConfig: Prevent "Error invoking callback" if core.json not found (#…
Browse files Browse the repository at this point in the history
  • Loading branch information
markus-wa authored Sep 19, 2024
1 parent 8f59fd5 commit 4b1a2c4
Showing 1 changed file with 17 additions and 16 deletions.
33 changes: 17 additions & 16 deletions managed/CounterStrikeSharp.API/Core/CoreConfig.cs
Original file line number Diff line number Diff line change
Expand Up @@ -151,27 +151,28 @@ public void Load()
_commandsRegistered = true;
}

if (!File.Exists(_coreConfigPath))
if (File.Exists(_coreConfigPath))
{
_logger.LogWarning(
"Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.",
_coreConfigPath);
return;
}

try
{
var data = JsonSerializer.Deserialize<CoreConfigData>(File.ReadAllText(_coreConfigPath),
new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip });

if (data != null)
try
{
var data = JsonSerializer.Deserialize<CoreConfigData>(File.ReadAllText(_coreConfigPath),
new JsonSerializerOptions() { ReadCommentHandling = JsonCommentHandling.Skip });

if (data != null)
{
_coreConfig = data;
}
}
catch (Exception ex)
{
_coreConfig = data;
_logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used");
}
}
catch (Exception ex)
else
{
_logger.LogWarning(ex, "Failed to load core configuration, fallback values will be used");
_logger.LogWarning(
"Core configuration could not be found at path \"{CoreConfigPath}\", fallback values will be used.",
_coreConfigPath);
}

var serverCulture = CultureInfo.GetCultures(CultureTypes.AllCultures)
Expand Down

0 comments on commit 4b1a2c4

Please sign in to comment.