clickhouse_dfe/dynamic/error.rs
1// SPDX-License-Identifier: Apache-2.0
2// Copyright (c) 2026 HYPERI PTY LIMITED
3
4// Project: clickhouse-dfe
5// File: src/dynamic/error.rs
6// Purpose: DynamicError for schema-driven inserts
7// Language: Rust
8//
9// License: Apache-2.0
10// Copyright: (c) 2026 HYPERI PTY LIMITED
11
12//! Error types for dynamic (schema-driven) inserts.
13
14/// Errors specific to dynamic schema-driven inserts.
15///
16/// `#[non_exhaustive]`: a caller matching on this must carry a `_` arm. The
17/// variants stay constructible so a consumer can build one in its own tests.
18#[derive(Debug, thiserror::Error)]
19#[non_exhaustive]
20pub enum DynamicError {
21 /// Column type string could not be parsed.
22 #[error("unsupported type '{type_str}' for column '{column}'")]
23 UnsupportedType {
24 /// Column the type was declared on.
25 column: String,
26 /// The type string as `system.columns` reported it.
27 type_str: String,
28 },
29 /// Value could not be encoded for the target column type.
30 #[error("encoding error for column '{column}': {message}")]
31 EncodingError {
32 /// Column the value belonged to; empty for a whole-row failure.
33 column: String,
34 /// What the encoder could not do.
35 message: String,
36 },
37 /// Schema mismatch detected -- server rejected the insert. Retriable once
38 /// the cached schema is invalidated.
39 #[error("schema mismatch for table '{table}': {message}")]
40 SchemaMismatch {
41 /// Fully qualified `database.table`.
42 table: String,
43 /// The server's rejection text.
44 message: String,
45 },
46 /// Schema fetch from `system.columns` failed. Retriable: a cold cache
47 /// after a restart hits this on a transport blip.
48 #[error("failed to fetch schema for '{table}': {source}")]
49 SchemaFetch {
50 /// Fully qualified `database.table`.
51 table: String,
52 /// The query failure, kept typed so a caller can classify it.
53 #[source]
54 source: clickhouse::error::Error,
55 },
56 /// Table has no columns (or does not exist). Retriable against a cluster
57 /// that is still replicating the DDL.
58 #[error("table '{table}' has no columns or does not exist")]
59 EmptySchema {
60 /// Fully qualified `database.table`.
61 table: String,
62 },
63}