fix(mtconnect): share MTConnectError text extraction; pin hollow-error refusal
This commit is contained in:
@@ -127,6 +127,40 @@ internal static class MTConnectXml
|
||||
return message;
|
||||
}
|
||||
|
||||
var errors = ExtractErrorText(root);
|
||||
|
||||
return errors is null ? message : $"{message} The Agent reported: {errors}";
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// The Agent's own words from an <c>MTConnectError</c> document: every <c><Error></c>
|
||||
/// beneath <paramref name="root"/>, rendered <c>errorCode: text</c> where a code is present
|
||||
/// and joined with <c>"; "</c>. <c>null</c> when the document carries no readable error
|
||||
/// detail at all (no <c><Error></c> elements, or only blank ones).
|
||||
/// </summary>
|
||||
/// <remarks>
|
||||
/// <para>
|
||||
/// <b>Shared because both callers must read the same document the same way.</b> An
|
||||
/// Agent's objection reaches this driver through two unrelated doors — a read path that
|
||||
/// got an error document where it expected a model
|
||||
/// (<see cref="DescribeUnexpectedRoot"/>), and the write path deciding whether a 200
|
||||
/// actually accepted the observation. Two copies of this walk would drift on the same
|
||||
/// two silent rules the type-level remarks describe, and on the write side a missed
|
||||
/// <c><Error></c> does not merely degrade a message: it reads as a successful
|
||||
/// write.
|
||||
/// </para>
|
||||
/// <para>
|
||||
/// <b><c>null</c> means "no readable detail", NOT "not an error document".</b> Only the
|
||||
/// caller knows which document it is holding — check the root name first. A caller that
|
||||
/// treats a <c>null</c> here as "no error occurred" turns a hollow
|
||||
/// <c><MTConnectError/></c> into a success.
|
||||
/// </para>
|
||||
/// </remarks>
|
||||
/// <param name="root">The <c>MTConnectError</c> document's root element.</param>
|
||||
public static string? ExtractErrorText(XElement root)
|
||||
{
|
||||
ArgumentNullException.ThrowIfNull(root);
|
||||
|
||||
var errors = root.Descendants()
|
||||
.Where(e => IsNamed(e, "Error"))
|
||||
.Select(e =>
|
||||
@@ -139,8 +173,6 @@ internal static class MTConnectXml
|
||||
.Where(text => text.Length > 0)
|
||||
.ToList();
|
||||
|
||||
return errors.Count == 0
|
||||
? message
|
||||
: $"{message} The Agent reported: {string.Join("; ", errors)}";
|
||||
return errors.Count == 0 ? null : string.Join("; ", errors);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user