File tree Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Expand file tree Collapse file tree 2 files changed +32
-3
lines changed Original file line number Diff line number Diff line change @@ -152,9 +152,18 @@ private function parseErrorClickHouse(string $body)
152
152
return false ;
153
153
}
154
154
155
- private function hasErrorClickhouse (string $ body ): bool {
155
+ private function hasErrorClickhouse (string $ body , string $ contentType ): bool {
156
+ if (false === stripos ($ contentType , 'application/json ' )) {
157
+ return preg_match (self ::CLICKHOUSE_ERROR_REGEX , $ body ) === 1 ;
158
+ }
156
159
157
- return preg_match (self ::CLICKHOUSE_ERROR_REGEX , $ body ) === 1 ;
160
+ try {
161
+ json_decode ($ body , true , 512 , JSON_THROW_ON_ERROR );
162
+ } catch (\JsonException $ e ) {
163
+ return true ;
164
+ }
165
+
166
+ return false ;
158
167
}
159
168
160
169
/**
@@ -214,7 +223,7 @@ public function isError(): bool
214
223
return true ;
215
224
}
216
225
217
- if ($ this ->hasErrorClickhouse ($ this ->response ()->body ())) {
226
+ if ($ this ->hasErrorClickhouse ($ this ->response ()->body (), $ this -> response ()-> content_type () )) {
218
227
return true ;
219
228
}
220
229
Original file line number Diff line number Diff line change @@ -50,6 +50,26 @@ public function testIsErrorWithOkStatusCode()
50
50
$ this ->assertTrue ($ result ->isError ());
51
51
}
52
52
53
+ /**
54
+ * @link https://github.com/smi2/phpClickHouse/issues/223
55
+ * @see src/Statement.php:14
56
+ *
57
+ * The response data may legitimately contain text that matches the
58
+ * CLICKHOUSE_ERROR_REGEX pattern. This is particularly common when querying
59
+ * system tables like system.mutations, where error messages are stored as data
60
+ */
61
+ public function testIsNotErrorWhenJsonBodyContainsDbExceptionMessage ()
62
+ {
63
+ $ result = $ this ->client ->select (
64
+ "SELECT
65
+ 'mutation_123456' AS mutation_id,
66
+ 'Code: 243. DB::Exception: Cannot reserve 61.64 GiB, not enough space. (NOT_ENOUGH_SPACE) (version 24.3.2.23 (official build))' AS latest_fail_reason "
67
+ );
68
+
69
+ $ this ->assertEquals (200 , $ result ->getRequest ()->response ()->http_code ());
70
+ $ this ->assertFalse ($ result ->isError ());
71
+ }
72
+
53
73
/**
54
74
* @dataProvider dataProvider
55
75
*/
You can’t perform that action at this time.
0 commit comments