Name the datapoint in the counter type error (#320) - #570
Merged
Merged
Conversation
`Counter must have type "number"!` said nothing about which datapoint it meant. One reporter searched for the misconfigured one for over a year, and a second confirmed the same. The message now carries the ID and the type the datapoint actually has, and says what to change: Counter must have type "number", but "modbus.5.inputRegisters.30536_Quelle" is stored as "String". Change the storage type of this datapoint to "Number", or switch the counter option off. It is also logged once per datapoint instead of once per value. The repetition was half of the problem - the screenshot in the issue is a wall of the same line - and adding the ID without throttling would only have made that wall wider. Two warnings in the same path had the same flaw and the ID right at hand: `No Connection to database` in prepareTaskCheckTypeAndDbId() and in #readIdIndexAndType() now say which datapoint could not be stored or looked up. The text is built by counterTypeMismatch() in src/lib/errors.ts rather than inline, so it can be unit tested without importing main.ts - which pulls in @iobroker/adapter-core and exits when js-controller cannot be resolved. Covered in test/testErrors.js, which the CI unit list already runs. Co-Authored-By: Claude Opus 5 (1M context) <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.
Fixes #320.
Counter must have type "number"!said nothing about which datapoint it meant. The reporter asked for the ID in 2023; a second user commented that they had been living with it for over a year without being able to find the misconfigured datapoint, and a third eventually located theirs by reading the raw object JSON for"counter": true.Before / after
The ID is what makes it searchable; the actual type and the two ways out are what make it actionable without guessing.
Logged once per datapoint, not once per value
The check sits in
pushHistory, so the old message fired for every value of the misconfigured datapoint — the screenshot in the issue is a wall of the same line. Adding the ID without throttling would only have made that wall wider, so acounterTypeReportedflag on the datapoint reports it once. The flag lives on the per-datapoint config, whichobjectChangerebuilds, so correcting the configuration lets it report again if it is still wrong.Two siblings in the same path
No Connection to databaseappeared twice with the datapoint ID available right there and unused:prepareTaskCheckTypeAndDbId()→No connection to the database, cannot store the value of "<id>"#readIdIndexAndType()→No connection to the database, cannot look up "<id>"Verification
The text is built by
counterTypeMismatch()insrc/lib/errors.tsrather than inline, so it is unit testable without importingmain.ts— which pulls in@iobroker/adapter-coreand exits the process when js-controller cannot be resolved (the constraint #567 established). Two cases added totest/testErrors.js, which the CI unit list already runs: that the ID, the current type, the target type and the alternative all appear and stay on one line, and that an unmapped storage type does not produce"undefined".144 unit tests pass;
check:tsandprettier --checkare clean on the changed files. (prettier --check README.mdreports findings already present on master, so the file is left as it is apart from the changelog line.)🤖 Generated with Claude Code