check_config: assert INI datatypes before comparing limits#4190
Open
tzuohann wants to merge 1 commit into
Open
check_config: assert INI datatypes before comparing limits#4190tzuohann wants to merge 1 commit into
tzuohann wants to merge 1 commit into
Conversation
A user who puts an inline comment on a limit line -- e.g.
"MAX_LIMIT = 100 # travel", easy to do without carefully reading the
manual -- is currently served a very confusing error. The check reports
a phantom limit violation like "[JOINT_0]MAX_LIMIT < [AXIS_X]MAX_LIMIT
(100 < {100 # travel})", which appears to claim 100 < 100 and points
at the wrong problem entirely.
The cause: the [JOINT_n]/[AXIS_L] limit check compares values with Tcl
> / <, which silently falls back to *string* comparison when a value
isn't a valid number (the stray comment text makes it a string). The
result then depends on trailing whitespace rather than the numbers. A
duplicated key behaved the same way, since the multi-valued list was
compared as a string.
Add assert_ini_datatypes(), run once right after parse_ini, before any
comparison. For each [JOINT_n]/[AXIS_L] item it validates the value
LinuxCNC actually uses -- the first occurrence (IniFile::Find defaults
to num=1; the manual, 'The INI File' -> 'Comments', likewise states the
first value is used):
- numeric items (limits, vels, accels, scales, PID terms, home vels,
...) must pass `string is double` (accepts ints and reals);
- enum items must match a fixed set, case-insensitively, mirroring
LinuxCNC's own caseless parsers:
TYPE -> {LINEAR ANGULAR} (IniFile::mapJointType)
bools -> {TRUE YES 1 ON FALSE NO 0 OFF} (IniFile::convertBool)
- unknown items are left untouched.
A non-numeric value whose text contains '#' or ';' additionally reports
that inline comments are not allowed and cites the manual section, so the
user is pointed at the real mistake.
Duplicate (multi-valued) [JOINT_]/[AXIS_] keys are not fatal -- LinuxCNC
uses the first occurrence -- so they emit a warning and the array is
collapsed to that first value so the downstream limit comparison uses it
too. This subsumes the warn-only warn_for_multiple_ini_values, which is
removed.
Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
A user who puts an inline comment on a limit line — e.g.
MAX_LIMIT = 100 # travel, easy to do without carefully reading the manual — is currently served a very confusing error from the pre-run config check:It appears to claim
100 < 100and points at the wrong problem entirely (a phantom joint/axis limit violation), when the real issue is the stray inline comment.Cause: the
[JOINT_n]/[AXIS_L]limit check incheck_config.tclcompares values with Tcl>/<, which silently falls back to string comparison when a value isn't a valid number. The comment text makes the value a string, so the outcome depends on trailing whitespace rather than the numbers. A duplicated key behaves the same way (the multi-valued list is compared as a string).This affects all of 2.9 — the inline-comment-stripping parser rewrite only exists in master/2.10.
Reproduce
Minimal trivkins config (
bad.ini):Run the checker against it:
Before this patch it reports the phantom
[JOINT_0]MAX_LIMIT < [AXIS_X]MAX_LIMIT (100 < {100 # travel}).Fix
Add
assert_ini_datatypes(), run once right afterparse_ini, before any comparison. For each[JOINT_n]/[AXIS_L]item it validates the value LinuxCNC actually uses — the first occurrence (IniFile::Finddefaults tonum=1; the manual, The INI File → Comments, likewise states the first value is used):string is double;TYPE→ LINEAR/ANGULAR; bool set for HOME_*, VOLATILE_HOME, LOCKING_INDEXER).A non-numeric value containing
#or;additionally reports that inline comments are not allowed and cites the manual section, so the user is pointed at the real mistake:Duplicate (multi-valued) keys are not fatal — LinuxCNC uses the first occurrence — so they emit a warning and the array is collapsed to that first value (so the downstream limit comparison uses the same value LinuxCNC would). This subsumes the warn-only
warn_for_multiple_ini_values, which is removed.Testing
Verified with minimal trivkins configs: