review(Driver.TwinCAT.Cli): clean parse errors + FlushLogging() in finally

Re-review at 7286d320. -008 (Low): ParseValue maps FormatException/OverflowException to a
clean CommandException (was raw stack trace) + tests. -009: FlushLogging() in all 5 commands'
finally blocks (parity with AbCip.Cli).
This commit is contained in:
Joseph Doherty
2026-06-19 12:08:45 -04:00
parent f8bf067243
commit 7580e37807
7 changed files with 154 additions and 26 deletions
@@ -141,12 +141,33 @@ public sealed class WriteCommandParseValueTests
() => WriteCommand.ParseValue("42", TwinCATDataType.Structure));
}
/// <summary>Verifies that ParseValue non-numeric for numeric types throws.</summary>
/// <summary>
/// Verifies that ParseValue wraps raw parse errors in a CommandException so the operator
/// sees a clean one-line message (Driver.TwinCAT.Cli-008).
/// </summary>
[Fact]
public void ParseValue_non_numeric_for_numeric_types_throws()
public void ParseValue_non_numeric_for_numeric_types_throws_CommandException()
{
Should.Throw<FormatException>(
// Previously threw raw FormatException. After the fix, FormatException + OverflowException
// are caught and re-thrown as CommandException so CliFx prints a single error line.
var ex = Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("xyz", TwinCATDataType.DInt));
ex.Message.ShouldContain("xyz");
ex.Message.ShouldContain("DInt");
}
/// <summary>
/// Verifies that ParseValue wraps OverflowException (value out of type range) in a
/// CommandException (Driver.TwinCAT.Cli-008).
/// </summary>
[Fact]
public void ParseValue_overflow_for_numeric_types_throws_CommandException()
{
// 300 is out of range for SInt (sbyte: -128..127).
var ex = Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("300", TwinCATDataType.SInt));
ex.Message.ShouldContain("300");
ex.Message.ShouldContain("SInt");
}
/// <summary>Verifies that SynthesiseTagName preserves symbolic path verbatim.</summary>