Skip to content

fix(send-receive): refuse token arguments that read_csv dropped - #163

Merged
ssweber merged 1 commit into
mainfrom
fix/sr-unknown-kw
Nov 20, 2026
Merged

ssweber merged 1 commit into
mainfrom
fix/sr-unknown-kw

Conversation

@ssweber

@ssweber ssweber commented Nov 20, 2026

Copy link
Copy Markdown
Owner

send(...) and receive(...) tokens now refuse arguments they used to drop or misread. Coil and Copy already refuse these. The change applies to read_csv, Send.from_csv_token() and Receive.from_csv_token().

Behaviour changes

  1. CsvReadError for an argument that can't be read. This covers an argument of a send, a receive, a target or a ModbusAddress(...) that:

    • has no keyword;
    • is written twice;
    • is not one of the call's keywords;
    • is empty;
    • runs into the next argument because a comma is missing.

    v0.4.0 dropped these, or read them into another field. For example, send(DS9,...) lost DS9, sucess=C2 was dropped, and dest= on a send gave a blank source.

  2. A target of neither kind raises CsvReadError. This is a target that is neither ModbusTcpTarget(...) nor ModbusRtuTarget(...), such as target=garbage. v0.4.0 raised a plain ValueError here, and main raised FieldError (invalid-token). CsvReadError subclasses ValueError.

  3. A quote in a Modbus target name is written twice. read_csv reads it back once, so to_csv then from_csv_token round-trips a name such as a"b"c. A file that v0.4.0 wrote for such a name now raises CsvReadError, or reads as another name.

A keyword that belongs to the other class gets the right keyword in the message: send(...) has dest=. Only receive(...) accepts it. Write source=DS1 instead.

A missing comma between two of the send's own values, such as success=C2 error=C3, still raises that field's FieldError, as in v0.4.0.

Checks

  • Fixture tokens: every Send and Receive token in the coverage goldens, the scr coverage CSV and the editor-grid answers reads and builds the same instruction as before.
  • Refusal paths: each refused form goes through both read_csv and from_csv_token, with the same class and message apart from the location.
  • Round trips: the reviewer built 28 awkward target names and round-tripped each through both paths: to_csv then from_csv_token, and read_csv then write_csv then read_csv.

Follow-ups (not in this PR)

  • Stale advice: some Send/Receive FieldError messages still advise quantity=N, which CSV refuses.
  • Generic message: a positional argument after a keyword still gets the generic token-parser message.

Gate

  • make lint: passed.
  • make docs-build: passed.
  • make test: 18969 passed, 139 skipped.

read_csv, Send.from_csv_token() and Receive.from_csv_token() now raise
CsvReadError for an argument of a send, a receive, a target or a
ModbusAddress(...) that has no keyword, is written twice, is not one of
the call's keywords, is empty, or runs into the next argument because a
comma is missing. A keyword of the other class is refused with the
keyword to write instead. A target that is neither a ModbusTcpTarget
nor a ModbusRtuTarget raises CsvReadError instead of FieldError.

Send.to_csv(), Receive.to_csv() and write_csv write each quote in a
target's name twice, and read_csv reads it back once, so a name with a
quote round-trips.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
@ssweber
ssweber merged commit 2a5e4b8 into main Nov 20, 2026
7 checks passed
@ssweber
ssweber deleted the fix/sr-unknown-kw branch November 20, 2026 01:46
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant