fix(driver-abcip-cli): resolve Medium code-review findings (Driver.AbCip.Cli-001, -002)

Driver.AbCip.Cli-001: WriteCommand.ParseValue wraps FormatException/
OverflowException as CommandException so bad --value input yields a clean
CLI error instead of a raw stack trace.
Driver.AbCip.Cli-002: probe/read/subscribe commands reject Structure types
up front (RejectStructure helper), matching the write guard.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 09:14:41 -04:00
parent e8edf123ff
commit 29e656912e
7 changed files with 78 additions and 22 deletions

View File

@@ -81,12 +81,33 @@ public sealed class WriteCommandParseValueTests
}
[Fact]
public void ParseValue_non_numeric_for_numeric_types_throws()
public void ParseValue_non_numeric_for_numeric_types_throws_CommandException()
{
Should.Throw<FormatException>(
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("xyz", AbCipDataType.DInt));
}
[Fact]
public void ParseValue_out_of_range_throws_CommandException()
{
// sbyte max is 127; 999 overflows it.
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("999", AbCipDataType.SInt));
}
[Theory]
[InlineData("12x", AbCipDataType.Int)]
[InlineData("3.14", AbCipDataType.DInt)]
[InlineData("99999999999", AbCipDataType.Int)]
public void ParseValue_bad_input_CommandException_message_is_actionable(
string raw, AbCipDataType type)
{
var ex = Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue(raw, type));
ex.Message.ShouldContain(raw);
ex.Message.ShouldContain(type.ToString());
}
[Theory]
[InlineData("Motor01_Speed", AbCipDataType.Real, "Motor01_Speed:Real")]
[InlineData("Program:Main.Counter", AbCipDataType.DInt, "Program:Main.Counter:DInt")]