> ## Documentation Index
> Fetch the complete documentation index at: https://clickhouse.com/docs/llms.txt
> Use this file to discover all available pages before exploring further.

# Why does system.errors show errors for queries that succeeded?

> system.errors counts every exception the server raises, including those it handles internally, so a counter can grow while all queries succeed. Use system.query_log to find real failures.

[`system.errors`](https://clickhouse.com/docs/reference/system-tables/errors) has one counter per error code, and a counter is incremented when the server raises an exception with that code. The table does not know whether the exception later failed a query or was caught and handled inside the server. A non-zero counter therefore does not mean that a query failed. To find queries that failed, use [`system.query_log`](https://clickhouse.com/docs/reference/system-tables/query_log).

## Example: a skipped row

The [`input_format_allow_errors_num`](https://clickhouse.com/docs/reference/settings/formats/input-format#input_format_allow_errors_num) setting lets a query skip rows that cannot be parsed. The second row below has text where a number is expected:

```sql theme={null}
SELECT *
FROM format(CSV, 'id UInt32, name String', '1,first\nabc,second\n3,third\n')
SETTINGS input_format_allow_errors_num = 1;
```

```text theme={null}
   ┌─id─┬─name──┐
1. │  1 │ first │
2. │  3 │ third │
   └────┴───────┘
```

The query succeeds and returns the two valid rows. The parser still raised an exception for the bad row before the row was skipped, and `system.errors` counted it:

```sql theme={null}
SELECT
    name,
    code,
    value,
    last_error_message
FROM system.errors
WHERE name = 'CANNOT_PARSE_INPUT_ASSERTION_FAILED'
FORMAT Vertical;
```

```text theme={null}
Row 1:
──────
name:               CANNOT_PARSE_INPUT_ASSERTION_FAILED
code:               27
value:              1
last_error_message: Cannot parse input: expected ',' before: 'abc,second\n3,third\n'
```

The `query_id` column of `system.errors` holds the query that raised the last exception of each kind. Joining it with `system.query_log` shows that this query finished without an exception:

```sql theme={null}
SYSTEM FLUSH LOGS;

SELECT
    e.name AS counted_error,
    q.type,
    q.exception_code
FROM system.errors AS e
INNER JOIN system.query_log AS q ON q.query_id = e.query_id
WHERE e.name = 'CANNOT_PARSE_INPUT_ASSERTION_FAILED'
    AND q.type != 'QueryStart';
```

```text theme={null}
   ┌─counted_error───────────────────────┬─type────────┬─exception_code─┐
1. │ CANNOT_PARSE_INPUT_ASSERTION_FAILED │ QueryFinish │              0 │
   └─────────────────────────────────────┴─────────────┴────────────────┘
```

## Example: format detection

Some features work by trying an operation and handling the failure. When you do not name the format of the data, ClickHouse [detects the format](https://clickhouse.com/docs/concepts/features/operations/insert/schema-inference.md#automatic-format-detection) by trying the candidates one after another. Each attempt that does not fit raises an exception inside the server:

```sql theme={null}
SELECT * FROM format('10,20,30\n40,50,60');
```

```text theme={null}
   ┌─c1─┬─c2─┬─c3─┐
1. │ 10 │ 20 │ 30 │
2. │ 40 │ 50 │ 60 │
   └────┴────┴────┘
```

```sql theme={null}
SELECT
    name,
    value
FROM system.errors
ORDER BY name;
```

On a freshly started test instance that ran only the two queries of this article, the table now contains four error codes, although no query failed (the exact list depends on the version):

```text theme={null}
   ┌─name────────────────────────────────┬─value─┐
1. │ ATTEMPT_TO_READ_AFTER_EOF           │     1 │
2. │ CANNOT_PARSE_INPUT_ASSERTION_FAILED │     8 │
3. │ INCORRECT_DATA                      │     6 │
4. │ UNKNOWN_TYPE                        │     1 │
   └─────────────────────────────────────┴───────┘
```

## Where the errors come from

The counters are server-wide and cumulative since the server started. They include:

* exceptions that the server raises and handles while a query succeeds, as in the examples above;
* exceptions of background operations, for example a mutation that fails and is retried, which happen outside of any query;
* failed queries of every user and application, including the ones that a client retried successfully;
* exceptions received from other servers during distributed queries, counted in separate rows with `remote = 1`.

Where the data is parsed also matters, and for `clickhouse-client` it depends on the insert:

* Data that follows the query text (`INSERT ... FORMAT CSV` with the rows after it, or `INSERT ... VALUES`) is sent to the server as text when the insert is asynchronous (`async_insert = 1`, the default since ClickHouse 26.2) or when the client runs with `--inline-insert-data`. The server parses it and counts the parsing exceptions, and the client reports the error as `Received exception from server`.
* Data of a synchronous insert (`async_insert = 0`), and data that the client reads from standard input or with `FROM INFILE`, is parsed by the client. These parsing errors are reported as `Error on processing query` and never reach the server.

Over the HTTP interface the server parses the data, and its parsing exceptions are counted on the server.

> [!NOTE]
>
> Before ClickHouse 26.8, an ordinary `INSERT ... VALUES` could increment parse error counters such as `CANNOT_PARSE_INPUT_ASSERTION_FAILED`: when the fast parser of the `Values` format could not read a value, the value was parsed again as an SQL expression, and the failed first attempt was counted although the insert succeeded. Starting with 26.8 these attempts are no longer counted.

## How to find real failures

Queries that failed are in `system.query_log` with the type `ExceptionBeforeStart` or `ExceptionWhileProcessing`:

```sql theme={null}
SELECT
    errorCodeToName(exception_code) AS error,
    count() AS failed_queries
FROM system.query_log
WHERE type IN ('ExceptionBeforeStart', 'ExceptionWhileProcessing')
    AND event_time >= now() - INTERVAL 1 HOUR
GROUP BY error
ORDER BY failed_queries DESC;
```

Use `system.errors`, and its history in [`system.error_log`](https://clickhouse.com/docs/reference/system-tables/error_log), as a hint that something happens on the server, and alert on a counter only if you know that the error code cannot be raised during normal operation. The reference page of `system.errors` gives the same advice.
