Send a usable payload from the Test connection button (#355) - #579
Merged
Merged
Conversation
"Test connection" reported a failure while the adapter was happily writing to the same database. The error read "invalid config", which sent people looking at settings that were fine. It is not a database error at all. The adapter sends that string from exactly one place: when `msg.message.config` is missing, i.e. when the request arrives with no settings. The database is never contacted. The payload came from a text template that is substituted and then JSON.parsed by the admin, which logs a parse failure to the browser console and sends the message with `null`. So anything that made the template produce invalid JSON turned into "invalid config" with no visible explanation. `encrypt` and `rejectUnauthorized` were interpolated without quotes, so an unset checkbox produced `"encrypt": undefined`; a value containing a newline broke it too - the admin escapes quotes and backslashes, but not control characters. Every value now goes through JSON.stringify, which quotes and escapes it and turns a missing one into a usable literal. Verified against the previously breaking inputs: unset checkboxes, quotes, backslashes, newlines and a completely empty configuration all produce valid JSON now. The template also left out three settings that testConnection() reads: - `doNotCreateDatabase`, which meant the PostgreSQL branch always tested the maintenance database `postgres`. That is the defect behind #285, and #562 fixed it in the adapter without the button ever sending the flag, so the fix could not take effect. - `dbname`, so the fallback would have used "iobroker" rather than the configured name. - `dockerMysql`, so a containerised instance was tested against whatever stale host and credentials the fields still held instead of the container's. And the message itself now says what happened rather than blaming the configuration, translated into all ten languages. 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 #355. "Test connection" reported a failure while the adapter was happily writing to the same database — and the message, "invalid config", sent the reporter looking at settings that were fine.
It is not a database error
The adapter sends that string from exactly one place:
The request arrived with no settings at all. The database is never contacted, which is why everything else kept working.
Why the settings went missing
The payload is a text template, substituted and then parsed by the admin:
A parse failure is logged to the browser console only and the message is sent with
null. So anything that made the template produce invalid JSON became "invalid config" with no visible explanation.encryptandrejectUnauthorizedwere interpolated without quotes, so an unset checkbox produced"encrypt": undefined. A value containing a newline broke it too — the admin'sescapeString()handles quotes and backslashes, but not control characters.Every value now goes through
JSON.stringify, which quotes and escapes it and turns a missing one into a usable literal. Checked against the inputs that used to break:encryptcheckbox"\Three settings were never sent
testConnection()reads them, the template did not include them:doNotCreateDatabase— so the PostgreSQL branch always tested the maintenance databasepostgres. That is the defect behind Connection to PostgreSQL fails due to relative file paths #285, and PostgreSQL: connect directly to the configured database when told not to create it #562 fixed it in the adapter while the button never sent the flag, so the fix could not take effect. This is what makes it work.dbname— the fallback would have usediobrokerrather than the configured name.dockerMysql— soapplyDockerMysqlConfig()never ran in the test path and a containerised instance was tested against whatever stale host and credentials the hidden fields still held. That alone produces exactly the reported shape: test red, operation green.And the message
It now says what happened — "The test request arrived without a configuration" — instead of blaming the configuration. Translated into all ten languages and registered in the button's error map.
Verification
npm run check:ts,npm run lint(both passes) andprettier --checkare clean; 192 unit tests pass. The template was evaluated the way the admin does it (a template literal withdatain scope) against each case in the table above, anddoNotCreateDatabase: truewithdbname: "meine_db"now arrives intact.One correction to my own first reading: I initially thought quotes and backslashes in a password broke the template. The admin's
escapeString()already rewrites those tokens, so that case is covered on current admin versions — it may explain the report on the 2024 version the reporter used, but I cannot verify that. The unquoted booleans, the control characters and the three missing settings are the parts that are demonstrably broken today.🤖 Generated with Claude Code