Skip to content

Name the setting when its value is rejected - #116882

Merged
alexey-milovidov merged 14 commits into
masterfrom
improve-setting-value-error-messages
Sep 24, 2026
Merged

alexey-milovidov merged 14 commits into
masterfrom
improve-setting-value-error-messages

Conversation

@alexey-milovidov

@alexey-milovidov alexey-milovidov commented Aug 28, 2026 •

Copy link
Copy Markdown
Member

Related: #116806
Related: #116809
Related: #116812
Related: #116815
Related: #116817
Related: #116871
Related: #116877

A survey pass over settings, table functions and window functions — as part of the wider survey of error messages for mistakes in SQL queries — found most of those answered well (an unknown setting is corrected, a bad enum lists the accepted values, an unknown table function and a bad window frame are named). One thing was not: a setting given a value of the wrong type or out of range is reported without saying which setting it was.

query before
SELECT 1 SETTINGS max_threads = 'abc' Cannot parse input: expected 'eof' before: 'abc'
SELECT 1 SETTINGS max_block_size = 0 A setting's value has to be greater than 0
SELECT 1 SETTINGS max_threads = -1 Field value -1 is out of range of unsigned long type
SELECT 1 SETTINGS max_memory_usage = '10 elephants' Cannot parse input: expected 'eof' before: ' elephants'

None of them names the setting, which for a query or a profile with a long SETTINGS list leaves the user to guess. The messages come from the setting's own field, which does not know its name — but the two places that reach it do. castValueUtil is where a value from a SETTINGS clause or from SET is checked, and set is where one from the server config is applied, so the context goes there, and stringToValueUtil right next to them, which converts settings profiles and constraints from users.xml, now uses the same wording:

Cannot parse input: expected 'eof' before: 'abc': while setting 'max_threads' to value 'abc'
A setting's value has to be greater than 0: while setting 'max_block_size' to value 0
Field value -1 is out of range of unsigned long type: while setting 'max_threads' to value -1

An unknown setting name is deliberately left alone — that message already names it and suggests a correction — so the lookup happens outside the block that adds the context:

Unknown setting 'max_threadz': Maybe you meant ['max_threads'].

SettingFieldURI used to build Poco::URI directly, so a malformed URI value (SETTINGS format_avro_schema_registry_url = 'http://[') escaped as a Poco::SyntaxException that is not a DB::Exception and bypassed the context. It is now converted into a BAD_ARGUMENTS exception, and the value echoed in the context goes through maskURIPassword, so a URI setting that carries basic-auth credentials is reported as http://user:[HIDDEN]@.... The same masking applies on the string-based stringToValueUtil path, so a malformed URI in a users.xml profile or constraint does not leak the password in the startup exception either.

ServerSettings::loadSettingsFromConfig had its own while parsing setting '{}' value wrapper for the config path, which is now redundant; it is removed so that one place produces the context for every path, and test_validate_threadpool_writer_pool_size is updated for the wording it produces instead (the same information).

The 79 stateless tests that mention UNKNOWN_SETTING, CANNOT_CONVERT_TYPE or a rejected setting value were run; the failures are unrelated environment ones (no ZooKeeper, no test clusters, no external databases in the local setup).

Changelog category (leave one):

  • Improvement

Changelog entry (a user-readable short description of the changes that goes into CHANGELOG.md):

A setting given a value of the wrong type or out of range now names the setting and the value in the error message — Cannot parse input: expected 'eof' before: 'abc': while setting 'max_threads' to value 'abc' instead of just Cannot parse input: expected 'eof' before: 'abc'. Previously the message came from the setting's field, which does not know its own name, so a query with a long SETTINGS list gave no clue which setting was at fault.


Workflow [PR]
Sync PR [sync-upstream/pr/116882]

Version info

  • Merged into: 26.10.1.621-master (included in 26.10 and later)

A survey pass over settings, table functions and window functions found
that a setting given a value of the wrong type or out of range is
reported without saying which setting it was:

    SELECT 1 SETTINGS max_threads = 'abc'
    Cannot parse input: expected 'eof' before: 'abc'

    SELECT 1 SETTINGS max_block_size = 0
    A setting's value has to be greater than 0

    SELECT 1 SETTINGS max_threads = -1
    Field value -1 is out of range of unsigned long type

The message is produced by the setting's own field, which does not know
its name. `castValueUtil` is where a value from a `SETTINGS` clause or
from `SET` is checked, and `set` is where one from the server config is
applied, so name the setting and the value there - which is what
`stringToValueUtil` next to them already does for the command line:

    Cannot parse input: expected 'eof' before: 'abc': while setting
    'max_threads' to value 'abc'

An unknown setting name is left alone: that message already names it and
suggests a correction, so the lookup happens outside the block that adds
the context.

`ServerSettings::loadSettingsFromConfig` had its own "while parsing
setting '{}' value" wrapper, which is now redundant, so it is removed and
`test_validate_threadpool_writer_pool_size` is updated for the wording it
produces instead - the same information, in the same place for all paths.
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Workflow [PR], commit [efc493e]

Summary: ✅


AI Review

Summary

This PR improves rejected-setting diagnostics across query, config, and users.xml paths, and the earlier URI-password leaks are fixed. One settings path still misses the new context, though: compatibility is handled outside the common wrapper, so the PR does not yet satisfy its own “name the setting when its value is rejected” contract for all settings.

Findings
  • ⚠️ Major: [src/Core/Settings.cpp:9973-9977, src/Common/ClickHouseVersion.cpp:18-31] compatibility is special-cased before BaseSettings::set, so malformed values still throw the bare Cannot parse ClickHouse version here: ... diagnostic with no while setting 'compatibility' to value ... suffix. A query like SELECT 1 SETTINGS compatibility = '26.bad', max_threads = 'abc' therefore still leaves the user guessing which setting failed, which is exactly the ambiguity this PR claims to remove.
    Suggested fix: wrap the applyCompatibilitySetting branch with the same while setting ... context that the other setting paths now add, and add a focused stateless regression for invalid compatibility in both SET and SETTINGS.
Final Verdict

Changes requested.

LLVM Coverage Report

Measured on commit efc493e.

Metric Baseline Current Δ
Lines 88.10% 88.10% +0.00%
Functions 91.70% 91.70% +0.00%
Branches 79.40% 79.50% +0.10%

Changed lines: Changed C/C++ lines covered: 45/54 (83.33%) · Uncovered code

Full report · Diff report

@clickhouse-gh clickhouse-gh Bot added the pr-improvement Pull request with some product improvements label Aug 28, 2026
`Fast test` reported

    Setting max_threadz is neither a builtin setting nor started with the prefix
    'SQL_' or 'custom_' registered for user-defined settings: Maybe you meant
    ['max_threads'].

where the test expected `Unknown setting 'max_threadz': Maybe you meant
['max_threads'].` - the wording depends on whether custom-setting prefixes
are configured, which the stateless test config does and a bare server
does not. Both forms are what this change is about leaving alone, so
assert the two things that matter instead of the text: the hint survives,
and no `: while setting ...` context is appended to it.
Comment thread src/Core/BaseSettings.h Resolved
@clickhouse-gh

clickhouse-gh Bot commented Aug 28, 2026 •

Copy link
Copy Markdown
Contributor

Build profile diff (arm_release)

Comparing efc493e66 with master da7ece5f9 (stripped binary size, per-symbol sizes and ThinLTO time; object sizes against the warmup build of 455029b82; compile times per translation unit against the most recent warmup build that recompiled it).

✅ No significant changes.

Binary sizes

programs/clickhouse-stripped: smaller than the master baseline by the known offset between the two builds, so the difference is not shown. A delta that differs from the offset by more than 50% of it is shown, in either direction.

The official master build is compiled with -g and a pull request build is not, and XRay counts debug instructions towards its instrumentation threshold, so master instruments thousands of functions more and its binary is ~0.4% larger no matter what the pull request does.

Compile time of recompiled translation units

1925 translation units recompiled, 11432 s compile time in total, 1925 of them have a recent master baseline.

Job report

…t the startup exception text outside `pytest.raises`

- Resolve the setting name outside the `try` in `BaseSettings::set`, the same way
  `castValueUtil` does, so an `UNKNOWN_SETTING` error from `getCustomSetting` does not
  get the `while setting ...` context appended (e.g. `CREATE TABLE ... ENGINE = Memory
  SETTINGS typo = 1` keeps its original diagnostic).
- In `test_validate_threadpool_writer_pool_size`, move the assertion below the
  `with pytest.raises(...)` block: `cluster.start()` raises, so the assertion was unreachable.
- In test 05052, normalize `unsigned long long` (macOS) to `unsigned long` (Linux) - the
  platform name of `UInt64` differs, which failed Fast test (arm_darwin):
  https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116882&sha=8c44211c61e5f27121676c1754c0afe631a12e89&name_0=PR&name_1=Fast%20test%20%28arm_darwin%29
  #116882
Master gained `05052_client_untrusted_server_allocations` and two 05053 tests, so the
test from this PR moves to the next free number.
The exception from `cluster.start` embeds the container's stdout, where the server only
reports `Server exited with 36` - the full exception text goes to the error log, which the
test already asserts on below. Verified by running the integration test locally: the message
`while setting 'threadpool_writer_pool_size' to value '0'` appears in the error log, and the
startup exception carries the exit code.
@alexey-milovidov

Copy link
Copy Markdown
Member Author

🕵 @groeneai, investigate the failure: https://s3.amazonaws.com/clickhouse-test-reports/json.html?PR=116882&sha=8c44211c61e5f27121676c1754c0afe631a12e89&name_0=PR&name_1=Stress%20test%20%28arm_msan%29 (Hung check failed, possible deadlock found — the hung thread is a MergeTree insert in MergeTreeDataPartWriterWide::writeColumn slowed by MSan poisoning, unrelated to this PR's error-message change; the same hung check failed on many unrelated PRs and on master over the last two weeks) and provide a fix in a separate PR. If the fix is already in progress, link it here.

Comment thread src/Core/BaseSettings.h Resolved
@groeneai

Copy link
Copy Markdown
Collaborator

The fix is already in progress: #108357 (Make column data write during INSERT respond to query cancellation).

I confirmed the attribution from hung_check.log. The hung thread's own frames:

__msan::PoisonMemory  <-  __sanitizer_dtor_callback_fields
DB::SerializationSparse::enumerateStreams
DB::MergeTreeDataPartWriterWide::getCurrentMarksForColumn
DB::MergeTreeDataPartWriterWide::writeColumn
DB::MergeTreeDataPartWriterWide::write
DB::MergedBlockOutputStream::writeWithPermutation
DB::MergeTreeDataWriter::writeTempPartImpl
DB::MergeTreeSink::consume

Its processlist row: is_cancelled: 1, elapsed: 475.03, query_kind: Insert, written_rows: 100000, query INSERT INTO mt_00160 (x) SELECT number AS x FROM system.numbers LIMIT 100000. It had already been cancelled and had no cancellation point at which to stop.

The carrier is 00160_merge_and_index_in_in.sql, which sets index_granularity = 1 and min_bytes_for_wide_part = 0, so those 100000 rows are 100000 Wide-part granules. Every mark-starting granule calls getCurrentMarksForColumn, which walks enumerateStreams, and MSan's use-after-dtor poisoning plus the stack-depot insert dominates that walk. 475 s over 100000 granules is about 4.75 ms per granule, four orders of magnitude below the hung-check window, so a per-granule cancellation point stops the query promptly rather than only narrowing the window.

#108357 adds checkWriteCancellation as the first statement of the for (const auto & granule : granules) loop in that same function, immediately ahead of the hung getCurrentMarksForColumn call. checkWriteCancellation has zero occurrences in src/ at 8c44211c6, so it is not on the tested tree, and it is the only open PR that introduces it.

In case tagging looks like the cheaper route: the test already carries -- Tags: no-msan (-- ^ slow) and has since 2025-07-22. The Stress test job runs clickhouse-test --stress-tests (ci/jobs/scripts/stress/stress.py:636), and that flag deliberately ignores no-<build> tags (tests/clickhouse-test:3129), so the tag does not apply in this job by design.

`SettingFieldURI` built `Poco::URI` directly, so a malformed value such as
`SETTINGS format_avro_schema_registry_url = 'http://['` escaped as a
`Poco::SyntaxException`, which is not a `DB::Exception` and therefore
bypassed the new "while setting '<name>' to value <value>" context.
`SettingFieldURI::parseURI` now converts it into a `BAD_ARGUMENTS` exception.

The echoed value is passed through `maskURIPassword`, so a URI setting that
carries basic-auth credentials does not print the password in the message.

The stateless test covers both: the setting is named and the password is masked.
Comment thread src/Core/BaseSettings.cpp Resolved
@clickhouse-gh clickhouse-gh Bot added the comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). label Sep 4, 2026
alexey-milovidov and others added 3 commits September 16, 2026 07:16
… too

`BaseSettings::stringToValueUtil`, which converts settings profiles and
constraints from `users.xml`, still appended the raw value to a rejected
value's message, so a malformed `format_avro_schema_registry_url` carrying
basic-auth credentials leaked the password in the startup exception.
Add a `String` overload of `BaseSettingsHelpers::formatValueForErrorMessage`
and route that path through it, using the same wording as the `Field`-based
`set` and `castValueUtil` paths. Also move the misplaced comment of
`warningSettingNotFound` back to it.

The new test drives the `users.xml` parser through `clickhouse-local` with a
config file that points `users_config` at itself, covering profiles and
constraints.

Co-Authored-By: Claude Fable 5.1 <[email protected]>
…ue-error-messages

# Conflicts:
#	src/Core/SettingsFields.cpp
Comment thread src/Core/BaseSettings.h
BaseSettingsHelpers::throwSettingNotFound(name);
}

/// This is where a value given in a `SETTINGS` clause or by `SET` is checked, so it is where the

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

compatibility still bypasses this new wrapper. SettingsImpl::set special-cases that name before it reaches BaseSettings::set (src/Core/Settings.cpp:9970-9974) and calls applyCompatibilitySetting directly, while ClickHouseVersion still throws a bare Cannot parse ClickHouse version here: ... for malformed input (src/Common/ClickHouseVersion.cpp:24-31).

As a result, SET compatibility = '26.bad' or SELECT 1 SETTINGS compatibility = '26.bad', max_threads = 'abc' still lacks the while setting 'compatibility' to value ... context this PR promises, so a long SETTINGS list can still leave the user guessing which setting failed. Please wrap that branch with the same suffix and add a focused stateless test for an invalid compatibility string.

@alexey-milovidov alexey-milovidov left a comment

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

All good.

@alexey-milovidov alexey-milovidov self-assigned this Sep 24, 2026
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 24, 2026
@github-merge-queue
github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Sep 24, 2026
Official builds end an exception message with `(version 26.10.1.1 (official build))`. The
`sed` pattern ` (version [^)]*)$` cannot match the nested parentheses, so the suffix stayed in
the output and `05059_setting_value_error_names_the_setting` failed in the merge queue, while it
passed on builds that print just `(version X)`. Strip everything from ` (version ` to the end
of the line instead, in both tests.

https://github.com/ClickHouse/ClickHouse/actions/runs/35940688467/job/107451385431

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
@alexey-milovidov
alexey-milovidov added this pull request to the merge queue Sep 24, 2026
Merged via the queue into master with commit ad356a7 Sep 24, 2026
176 checks passed
@alexey-milovidov
alexey-milovidov deleted the improve-setting-value-error-messages branch September 24, 2026 16:25
@robot-ch-test-poll4 robot-ch-test-poll4 added the pr-synced-to-cloud The PR is synced to the cloud repo label Sep 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

comp-settings Settings & configuration infrastructure (server/user/query settings, profiles). pr-improvement Pull request with some product improvements pr-synced-to-cloud The PR is synced to the cloud repo

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants