Made Config initialization errors more forgiving to noobs.

This commit is contained in:
MapleWheels
2026-04-08 19:38:18 -04:00
parent 3a5fbfde1e
commit 89aa818c0b
3 changed files with 11 additions and 4 deletions

View File

@@ -26,6 +26,9 @@ end)
local failed, package = trygetpackage("[DebugOnlyTest]TestLuaMod")
print("packageFailed=", failed)
print("package", package.Name)
local success, config = ConfigService.TryGetConfig(SettingBase.Single, package, "TestFloat")
print("config ", success, " ", config)

View File

@@ -1,5 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<ModConfig>
<Lua File="%ModDir%/Lua/init.lua" Target="Any" IsAutorun="true" />
<Lua File="%ModDir%/Lua/init.lua" IsAutorun="true" />
<Config File="%ModDir%/Settings.xml"/>
</ModConfig>

View File

@@ -325,6 +325,8 @@ public sealed partial class ConfigService : IConfigService
{
return FluentResults.Result.Ok();
}
var result = new FluentResults.Result();
var taskBuilder = ImmutableArray.CreateBuilder<Task<ImmutableArray<IConfigInfo>>>();
var toProcessErrors = new ConcurrentStack<IError>();
@@ -362,7 +364,9 @@ public sealed partial class ConfigService : IConfigService
{
if (!_instanceFactory.TryGetValue(info.DataType, out var factory))
{
return FluentResults.Result.Fail($"{nameof(LoadConfigsAsync)}: Could not retrieve the instance factory for the data type of '{info.DataType}'!");
result.WithError(
$"{nameof(LoadConfigsAsync)}: Could not retrieve the instance factory for the data type of '{info.DataType}'!");
continue;
}
if (_settingsInstances.ContainsKey((info.OwnerPackage, info.InternalName)))
{
@@ -383,13 +387,13 @@ public sealed partial class ConfigService : IConfigService
}
catch (Exception e)
{
FluentResults.Result.Fail(
result.WithError(
$"{nameof(LoadConfigsAsync)}: Error while instancing setting for '{instanceFactoryInfo.configInfo.OwnerPackage}.{instanceFactoryInfo.configInfo.InternalName}': {e.Message}!");
continue;
}
}
using var settingsLck = await _settingsByPackageLock.AcquireWriterLock(); // block to protect new bag instance creation
var result = new FluentResults.Result();
while (toProcessInstanceQueue.TryDequeue(out var newInstanceData))
{