fix(driver-modbus-addressing): resolve Medium code-review finding (Driver.Modbus.Addressing-003)
Complete the incomplete Addressing-003 fix: TryParseByteOrder now produces a diagnostic mentioning "field 2" when a known type-code token (e.g. BOOL) is supplied in the byte-order slot, so the user is guided to the correct field. The previous fix only wired the message in the else-branch, which was unreachable because LooksLikeByteOrderToken(BOOL) returned true first. Co-Authored-By: Claude Opus 4.7 (1M context) <noreply@anthropic.com>
This commit is contained in:
@@ -468,7 +468,14 @@ public static class ModbusAddressParser
|
||||
|
||||
if ((int)order == -1)
|
||||
{
|
||||
error = $"Unknown byte order '{text}'. Valid: ABCD, CDAB, BADC, DCBA";
|
||||
// Driver.Modbus.Addressing-003: if the unknown token looks like a known type code
|
||||
// (a 4-letter alphanumeric token that matches one of the recognised type strings),
|
||||
// produce a diagnostic that directs the user to put the type in field 2, not field 3.
|
||||
var isKnownTypeCode = text.ToUpperInvariant() is "BOOL" or "REAL" or "DINT" or "UINT"
|
||||
|| (text.Length <= 6 && text.StartsWith("STR", StringComparison.OrdinalIgnoreCase));
|
||||
error = isKnownTypeCode
|
||||
? $"'{text}' looks like a type code; type belongs in field 2 (e.g. '40001:{text.ToUpperInvariant()}'), not field 3. Field 3 must be a 4-letter byte order (ABCD/CDAB/BADC/DCBA)"
|
||||
: $"Unknown byte order '{text}'. Valid: ABCD, CDAB, BADC, DCBA";
|
||||
return false;
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user