fix(driver-ablegacy-cli): resolve Medium code-review finding (Driver.AbLegacy.Cli-001)

WriteCommand.ParseValue wraps FormatException/OverflowException as
CliFx CommandException so a bad --value yields a clean one-line CLI error
naming the value and target type instead of a raw .NET stack trace.

Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
Joseph Doherty
2026-05-22 09:15:19 -04:00
parent 29e656912e
commit 6bb971c040
3 changed files with 48 additions and 15 deletions

View File

@@ -72,12 +72,24 @@ 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>(
// Bad input must surface as CommandException (clean one-line error), not a raw FormatException.
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue("xyz", AbLegacyDataType.Int));
}
[Theory]
[InlineData("99999", AbLegacyDataType.Int)] // short range is ±32767
[InlineData("-99999", AbLegacyDataType.Int)]
[InlineData("-99999", AbLegacyDataType.AnalogInt)]
public void ParseValue_out_of_range_throws_CommandException(string raw, AbLegacyDataType type)
{
// Out-of-range values must surface as CommandException, not OverflowException.
Should.Throw<CliFx.Exceptions.CommandException>(
() => WriteCommand.ParseValue(raw, type));
}
[Theory]
[InlineData("N7:0", AbLegacyDataType.Int, "N7:0:Int")]
[InlineData("B3:0/3", AbLegacyDataType.Bit, "B3:0/3:Bit")]