fix(multivalue): NJ-3/NJ-4/NJ-5 review fixes

- NJ-3: widen per-row catch to Exception (an STJ encode failure can't abort startup); drop dead null-guard already excluded by the SQL filter
- NJ-4: capture logger/instanceName in locals for the fire-and-forget normalize continuation (match the sibling pattern in this actor)
- NJ-5: emit a warn-log when a malformed List value is imported verbatim; thread an optional ILogger<BundleImporter> to the sync re-import site
This commit is contained in:
Joseph Doherty
2026-06-16 18:25:42 -04:00
parent f4b101b532
commit feeae1371e
4 changed files with 32 additions and 19 deletions
@@ -1,3 +1,4 @@
using Microsoft.Extensions.Logging;
using ZB.MOM.WW.ScadaBridge.Commons.Types;
using ZB.MOM.WW.ScadaBridge.Commons.Types.Enums;
@@ -29,7 +30,14 @@ internal static class ImportValueNormalizer
/// <param name="value">The attribute value as carried by the bundle DTO.</param>
/// <param name="dataType">The attribute's declared data type.</param>
/// <param name="elementType">The List element type (null for scalars).</param>
public static string? NormalizeListValue(string? value, DataType dataType, DataType? elementType)
/// <param name="logger">Optional logger; a warning is emitted when a malformed value is left as-is.</param>
/// <param name="attributeName">Optional attribute name for the diagnostic message.</param>
public static string? NormalizeListValue(
string? value,
DataType dataType,
DataType? elementType,
ILogger? logger = null,
string? attributeName = null)
{
if (dataType != DataType.List || string.IsNullOrEmpty(value))
{
@@ -41,10 +49,14 @@ internal static class ImportValueNormalizer
return AttributeValueCodec.Encode(
AttributeValueCodec.Decode(value, DataType.List, elementType));
}
catch (FormatException)
catch (FormatException ex)
{
// Leave malformed values exactly as imported; the DB normalizer is
// the backstop. Never abort the import for a single bad value.
logger?.LogWarning(ex,
"Bundle import: could not normalize List value for attribute {Attribute}; " +
"importing verbatim (the central DB normalizer is the backstop).",
attributeName ?? "(unknown)");
return value;
}
}