Code Coverage
 
Lines
Functions and Methods
Classes and Traits
Total
100.00% covered (success)
100.00%
251 / 251
100.00% covered (success)
100.00%
15 / 15
CRAP
100.00% covered (success)
100.00%
1 / 1
ZErrorFactory
100.00% covered (success)
100.00%
251 / 251
100.00% covered (success)
100.00%
15 / 15
94
100.00% covered (success)
100.00%
1 / 1
 readYamlAsSecretJson
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 errorMatchesDescriptor
100.00% covered (success)
100.00%
15 / 15
100.00% covered (success)
100.00%
1 / 1
10
 getDataType
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
7
 errorMatchesType
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
3
 createZErrorList
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 createValidationZError
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 createAuthorizationZError
100.00% covered (success)
100.00%
16 / 16
100.00% covered (success)
100.00%
1 / 1
6
 createKeyValueZError
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 createArrayElementZError
100.00% covered (success)
100.00%
7 / 7
100.00% covered (success)
100.00%
1 / 1
1
 createLabelClashZErrors
100.00% covered (success)
100.00%
12 / 12
100.00% covered (success)
100.00%
1 / 1
3
 createZErrorInstance
100.00% covered (success)
100.00%
135 / 135
100.00% covered (success)
100.00%
1 / 1
55
 createTypedError
100.00% covered (success)
100.00%
1 / 1
100.00% covered (success)
100.00%
1 / 1
1
 createUnknownValidationError
100.00% covered (success)
100.00%
5 / 5
100.00% covered (success)
100.00%
1 / 1
1
 createEvaluationError
100.00% covered (success)
100.00%
11 / 11
100.00% covered (success)
100.00%
1 / 1
1
 createApiFailureError
100.00% covered (success)
100.00%
8 / 8
100.00% covered (success)
100.00%
1 / 1
2
1<?php
2/**
3 * WikiLambda interface for validation error formatting
4 *
5 * @file
6 * @copyright 2020– Abstract Wikipedia team; see AUTHORS.txt
7 * @license MIT
8 */
9
10namespace MediaWiki\Extension\WikiLambda;
11
12use MediaWiki\Extension\WikiLambda\Registry\ZErrorTypeRegistry;
13use MediaWiki\Extension\WikiLambda\Registry\ZTypeRegistry;
14use MediaWiki\Extension\WikiLambda\ZObjects\ZError;
15use MediaWiki\Extension\WikiLambda\ZObjects\ZKeyReference;
16use MediaWiki\Extension\WikiLambda\ZObjects\ZObject;
17use MediaWiki\Extension\WikiLambda\ZObjects\ZQuote;
18use MediaWiki\Extension\WikiLambda\ZObjects\ZReference;
19use MediaWiki\Extension\WikiLambda\ZObjects\ZString;
20use MediaWiki\Extension\WikiLambda\ZObjects\ZTypedError;
21use Symfony\Component\Yaml\Yaml;
22
23class ZErrorFactory {
24
25    /**
26     * @param string $yamlFile File to read
27     * @return string
28     */
29    public static function readYamlAsSecretJson( string $yamlFile ) {
30        return json_encode( Yaml::parseFile( $yamlFile ) );
31    }
32
33    /**
34     * @param array $error
35     * @param array $descriptor
36     * @return bool
37     */
38    public static function errorMatchesDescriptor( $error, $descriptor ): bool {
39        // 1. The descriptor keyword must be the same as the error keyword
40        if ( $error['keyword'] !== $descriptor['keyword'] ) {
41            return false;
42        }
43
44        // 2. Every item from the descriptor keywordArgs must be present in the error
45        foreach ( $descriptor['keywordArgs'] as $wantedArg => $wantedValue ) {
46            if ( !array_key_exists( $wantedArg, $error['keywordArgs'] ) ) {
47                return false;
48            }
49
50            if ( is_array( $wantedValue ) && !in_array( $error['keywordArgs'][ $wantedArg ], $wantedValue ) ) {
51                return false;
52            }
53
54            if ( is_string( $wantedValue ) && ( $error['keywordArgs'][ $wantedArg ] !== $wantedValue ) ) {
55                return false;
56            }
57        }
58
59        // 3. The descriptor dataPointer must match the tail of the error dataPointer
60        // 3.1. If the descriptor dataPointer is longer than the error dataPointer, not a match
61        if ( count( $descriptor['dataPointer'] ) > count( $error['dataPointer'] ) ) {
62            return false;
63        }
64
65        // 3.2 Get the tail of the error descriptor and check (with ===)
66        // that both arrays contain the same elements in the same order
67        if ( count( $descriptor['dataPointer'] ) > 0 ) {
68            $tail = array_slice( $error['dataPointer'], -( count( $descriptor['dataPointer'] ) ) );
69            return $descriptor['dataPointer'] === $tail;
70        }
71        // If the descriptor dataPointer is empty, return true
72        return true;
73    }
74
75    /**
76     * Given an error data field, which is the partial ZObject in which
77     * the error has been found, returns its data type if available
78     *
79     * @param array $data
80     * @return string|bool
81     */
82    public static function getDataType( $data ) {
83        // $data = json_decode( json_encode( $errorData ), true);
84        if ( !is_array( $data ) ) {
85            return false;
86        }
87
88        if ( !array_key_exists( ZTypeRegistry::Z_OBJECT_TYPE, $data ) ) {
89            return false;
90        }
91
92        if ( is_string( $data[ ZTypeRegistry::Z_OBJECT_TYPE ] ) ) {
93            return $data[ ZTypeRegistry::Z_OBJECT_TYPE ];
94        }
95
96        if (
97            array_key_exists( ZTypeRegistry::Z_OBJECT_TYPE, $data[ZTypeRegistry::Z_OBJECT_TYPE ] ) &&
98            ( $data[ ZTypeRegistry::Z_OBJECT_TYPE ][ ZTypeRegistry::Z_OBJECT_TYPE ] === ZTypeRegistry::Z_REFERENCE ) &&
99            array_key_exists( ZTypeRegistry::Z_REFERENCE_VALUE, $data[ ZTypeRegistry::Z_OBJECT_TYPE  ] )
100        ) {
101            return $data[ ZTypeRegistry::Z_OBJECT_TYPE ][ ZTypeRegistry::Z_REFERENCE_VALUE ];
102        }
103
104        return false;
105    }
106
107    /**
108     * Infers the type of the error data field and returns true if the
109     * missing key matches that type.
110     *
111     * @param array|string $error
112     * @return bool
113     */
114    public static function errorMatchesType( $error ): bool {
115        // Infer data type if we can
116        $dataType = self::getDataType( $error['data'] );
117        if ( !$dataType ) {
118            return true;
119        }
120
121      // If there's a missing key and an inferred type, match them
122        if ( !array_key_exists( 'missing', $error['keywordArgs'] ) ) {
123            return true;
124        }
125
126        $keyPrefix = $dataType . 'K';
127        $missingKey = $error['keywordArgs']['missing'];
128        return ( strpos( $missingKey, $keyPrefix ) === 0 );
129    }
130
131    /**
132     * Create a Z5/ZError of the type Z509/Multiple errors
133     *
134     * @param ZError[] $errorList
135     * @return ZError
136     */
137    public static function createZErrorList( $errorList ): ZError {
138        $errorsList = array_merge( [ new ZReference( ZTypeRegistry::Z_ERROR ) ], $errorList );
139        return self::createZErrorInstance(
140            ZErrorTypeRegistry::Z_ERROR_LIST,
141            [
142                // We don't need to catch the error thrown by ZObjectFactory::create because
143                // we know that every item of the list is already an instance of ZObject
144                'errorList' => ZObjectFactory::create( $errorsList )
145            ]
146        );
147    }
148
149    /**
150     * Create a Z5/ZError of the type Z502/Not wellformed
151     *
152     * @param ZError $childError
153     * @return ZError
154     */
155    public static function createValidationZError( ZError $childError ): ZError {
156        return self::createZErrorInstance(
157            ZErrorTypeRegistry::Z_ERROR_NOT_WELLFORMED,
158            [
159                'subtype' => $childError->getZErrorType(),
160                'childError' => $childError
161            ]
162        );
163    }
164
165    /**
166     * Create a Z5/ZError of the type Z502/Not wellformed
167     *
168     * @param string $right
169     * @param int $flags whether is edit EDIT_UPDATE or create EDIT_NEW
170     * @return ZError
171     */
172    public static function createAuthorizationZError( $right, $flags ): ZError {
173        $error = null;
174
175        switch ( $right ) {
176            case 'edit':
177            case 'wikilambda-create':
178            case 'wikilambda-edit':
179                $message = ( $flags === EDIT_NEW ) ? 'nocreatetext' : 'badaccess-group0';
180                $error = self::createZErrorInstance(
181                    ZErrorTypeRegistry::Z_ERROR_USER_CANNOT_EDIT,
182                    [ 'message' => wfMessage( $message )->text() ]
183                );
184                break;
185
186            default:
187                // Return descriptive error message using the right action message:
188                $message = wfMessage( 'apierror-permissiondenied', wfMessage( "action-$right" ) )->text();
189                $error = self::createZErrorInstance(
190                    ZErrorTypeRegistry::Z_ERROR_USER_CANNOT_EDIT,
191                    [ 'message' => $message ]
192                );
193        }
194
195        return $error;
196    }
197
198    /**
199     * Create a Z5/ZError of the type Z526/Key not wellformed
200     *
201     * @param string $key
202     * @param ZError $childError
203     * @return ZError
204     */
205    public static function createKeyValueZError( $key, $childError ): ZError {
206        return self::createZErrorInstance(
207            ZErrorTypeRegistry::Z_ERROR_KEY_VALUE_NOT_WELLFORMED,
208            [
209                'key' => $key,
210                'childError' => $childError
211            ]
212        );
213    }
214
215    /**
216     * Create a Z5/ZError of the type Z522/Array element not wellformed
217     *
218     * @param string $index
219     * @param ZError $childError
220     * @return ZError
221     */
222    public static function createArrayElementZError( $index, $childError ): ZError {
223        return self::createZErrorInstance(
224            ZErrorTypeRegistry::Z_ERROR_ARRAY_ELEMENT_NOT_WELLFORMED,
225            [
226                'index' => $index,
227                'childError' => $childError
228            ]
229        );
230    }
231
232    /**
233     * Create a ZError wrapping one or more label clashing errors
234     *
235     * @param array $clashes
236     * @return ZError
237     */
238    public static function createLabelClashZErrors( $clashes ): ZError {
239        $clashErrors = [];
240        foreach ( $clashes as $language => $clashZid ) {
241            $clashErrors[] = self::createZErrorInstance(
242                ZErrorTypeRegistry::Z_ERROR_LABEL_CLASH,
243                [
244                    'zid' => $clashZid,
245                    'language' => $language
246                ]
247            );
248        }
249
250        if ( count( $clashErrors ) > 1 ) {
251            return self::createZErrorList( $clashErrors );
252        }
253        return $clashErrors[0];
254    }
255
256    /**
257     * Create a Z5/ZError of a given Z50/ZErrorType
258     *
259     * @param string $zErrorType
260     * @param array $payload
261     * @return ZError
262     */
263    public static function createZErrorInstance( $zErrorType, $payload ): ZError {
264        $zErrorValue = [];
265
266        switch ( $zErrorType ) {
267            case ZErrorTypeRegistry::Z_ERROR_UNKNOWN:
268                $zErrorValue[] = new ZString( $payload['message'] );
269                break;
270
271            case ZErrorTypeRegistry::Z_ERROR_INVALID_SYNTAX:
272                $zErrorValue[] = new ZString( $payload['message'] );
273                $zErrorValue[] = new ZString( $payload['input'] );
274                break;
275
276            case ZErrorTypeRegistry::Z_ERROR_NOT_WELLFORMED:
277                $zErrorValue[] = new ZString( $payload['subtype'] );
278                $zErrorValue[] = $payload['childError'];
279                break;
280
281            case ZErrorTypeRegistry::Z_ERROR_ID_NOT_FOUND:
282                $zErrorValue[] = new ZString( $payload['data'] );
283                break;
284
285            case ZErrorTypeRegistry::Z_ERROR_EVALUATION:
286                $zErrorValue[] = new ZQuote( $payload['functionCall'] );
287                $zErrorValue[] = $payload['error'];
288                break;
289
290            case ZErrorTypeRegistry::Z_ERROR_LIST:
291                $zErrorValue[] = $payload['errorList'];
292                break;
293
294            case ZErrorTypeRegistry::Z_ERROR_MISSING_KEY:
295                $ref = array_key_exists( 'missing', $payload['keywordArgs'] ) ? $payload['keywordArgs']['missing'] : '';
296                $zErrorValue[] = new ZKeyReference( $ref );
297                $zErrorValue[] = new ZQuote( $payload['data'] );
298                break;
299
300            case ZErrorTypeRegistry::Z_ERROR_MISSING_PERSISTENT_VALUE:
301                $zErrorValue[] = new ZQuote( $payload['data'] );
302                break;
303
304            case ZErrorTypeRegistry::Z_ERROR_UNDEFINED_LIST_TYPE:
305                $zErrorValue[] = new ZQuote( $payload['data'] );
306                break;
307
308            case ZErrorTypeRegistry::Z_ERROR_WRONG_LIST_TYPE:
309                $zErrorValue[] = new ZQuote( $payload['data'] );
310                break;
311
312            case ZErrorTypeRegistry::Z_ERROR_NOT_NUMBER_BOOLEAN_NULL:
313                $zErrorValue[] = new ZQuote( $payload['data'] );
314                break;
315
316            case ZErrorTypeRegistry::Z_ERROR_ARRAY_ELEMENT_NOT_WELLFORMED:
317                $zErrorValue[] = new ZString( $payload['index'] );
318                $zErrorValue[] = $payload['childError'];
319                break;
320
321            case ZErrorTypeRegistry::Z_ERROR_MISSING_TYPE:
322                $zErrorValue[] = new ZQuote( $payload['data'] );
323                break;
324
325            case ZErrorTypeRegistry::Z_ERROR_TYPE_NOT_STRING_ARRAY:
326                $zErrorValue[] = $payload['data'];
327                break;
328
329            case ZErrorTypeRegistry::Z_ERROR_INVALID_KEY:
330                $zErrorValue[] = new ZString( end( $payload['dataPointer'] ) );
331                break;
332
333            case ZErrorTypeRegistry::Z_ERROR_KEY_VALUE_NOT_WELLFORMED:
334                $zErrorValue[] = new ZKeyReference( $payload['key'] );
335                $zErrorValue[] = $payload['childError'];
336                break;
337
338            case ZErrorTypeRegistry::Z_ERROR_STRING_VALUE_MISSING:
339                $zErrorValue[] = new ZQuote( $payload['data'] );
340                break;
341
342            case ZErrorTypeRegistry::Z_ERROR_STRING_VALUE_WRONG_TYPE:
343                $zErrorValue[] = new ZQuote( $payload['data'] );
344                break;
345
346            case ZErrorTypeRegistry::Z_ERROR_REFERENCE_VALUE_MISSING:
347                $zErrorValue[] = new ZQuote( $payload['data'] );
348                break;
349
350            case ZErrorTypeRegistry::Z_ERROR_REFERENCE_VALUE_WRONG_TYPE:
351                $zErrorValue[] = new ZQuote( $payload['data'] );
352                break;
353
354            case ZErrorTypeRegistry::Z_ERROR_REFERENCE_VALUE_INVALID:
355                $zErrorValue[] = new ZString( $payload['data'] );
356                break;
357
358            case ZErrorTypeRegistry::Z_ERROR_WRONG_NAMESPACE:
359                $zErrorValue[] = new ZString( $payload['title'] );
360                break;
361
362            case ZErrorTypeRegistry::Z_ERROR_WRONG_CONTENT_TYPE:
363                $zErrorValue[] = new ZString( $payload['title'] );
364                break;
365
366            case ZErrorTypeRegistry::Z_ERROR_INVALID_LANG_CODE:
367                $zErrorValue[] = new ZString( $payload['lang'] );
368                break;
369
370            case ZErrorTypeRegistry::Z_ERROR_LANG_NOT_FOUND:
371                $zErrorValue[] = new ZString( $payload['lang'] );
372                break;
373
374            case ZErrorTypeRegistry::Z_ERROR_UNEXPECTED_ZTYPE:
375                $zErrorValue[] = new ZReference( $payload['expected'] );
376                $zErrorValue[] = new ZReference( $payload['used'] );
377                break;
378
379            case ZErrorTypeRegistry::Z_ERROR_ZTYPE_NOT_FOUND:
380                $zErrorValue[] = new ZString( $payload['type'] );
381                break;
382
383            case ZErrorTypeRegistry::Z_ERROR_CONFLICTING_TYPE_NAMES:
384                $zErrorValue[] = new ZString( $payload['zid'] );
385                $zErrorValue[] = new ZString( $payload['name'] );
386                $zErrorValue[] = new ZString( $payload['existing'] );
387                break;
388
389            case ZErrorTypeRegistry::Z_ERROR_CONFLICTING_TYPE_ZIDS:
390                $zErrorValue[] = new ZString( $payload['zid'] );
391                $zErrorValue[] = new ZString( $payload['name'] );
392                $zErrorValue[] = new ZString( $payload['existing'] );
393                break;
394
395            case ZErrorTypeRegistry::Z_ERROR_BUILTIN_TYPE_NOT_FOUND:
396                $zErrorValue[] = new ZString( $payload['zid'] );
397                $zErrorValue[] = new ZString( $payload['name'] );
398                break;
399
400            case ZErrorTypeRegistry::Z_ERROR_INVALID_FORMAT:
401                $zErrorValue[] = new ZQuote( $payload['data'] );
402                break;
403
404            case ZErrorTypeRegistry::Z_ERROR_INVALID_JSON:
405                $zErrorValue[] = new ZString( $payload['message'] );
406                $zErrorValue[] = new ZQuote( $payload['data'] );
407                break;
408
409            case ZErrorTypeRegistry::Z_ERROR_INVALID_REFERENCE:
410                $zErrorValue[] = new ZString( $payload['data'] );
411                break;
412
413            case ZErrorTypeRegistry::Z_ERROR_UNKNOWN_REFERENCE:
414                $zErrorValue[] = new ZString( $payload['data'] );
415                break;
416
417            case ZErrorTypeRegistry::Z_ERROR_SCHEMA_TYPE_MISMATCH:
418                $keyRef = end( $payload['dataPointer'] );
419                $zErrorValue[] = new ZKeyReference( $keyRef ?: '' );
420                $zErrorValue[] = new ZString( $payload['keywordArgs']['expected'] );
421                $zErrorValue[] = new ZString( $payload['keywordArgs']['used'] );
422                break;
423
424            case ZErrorTypeRegistry::Z_ERROR_ARRAY_TYPE_MISMATCH:
425                $zErrorValue[] = new ZKeyReference( $payload['key'] );
426                $zErrorValue[] = new ZString( $payload['expected'] );
427                $zErrorValue[] = new ZQuote( $payload['data'] );
428                break;
429
430            case ZErrorTypeRegistry::Z_ERROR_DISALLOWED_ROOT_ZOBJECT:
431                $zErrorValue[] = new ZQuote( $payload['data'] );
432                break;
433
434            case ZErrorTypeRegistry::Z_ERROR_LABEL_CLASH:
435                $zErrorValue[] = new ZString( $payload['zid'] );
436                $zErrorValue[] = new ZString( $payload['language'] );
437                break;
438
439            case ZErrorTypeRegistry::Z_ERROR_UNMATCHING_ZID:
440                $zErrorValue[] = new ZString( $payload['zid'] );
441                $zErrorValue[] = new ZString( $payload['title'] );
442                break;
443
444            case ZErrorTypeRegistry::Z_ERROR_INVALID_TITLE:
445                $zErrorValue[] = new ZString( $payload['title'] );
446                break;
447
448            case ZErrorTypeRegistry::Z_ERROR_USER_CANNOT_EDIT:
449                $zErrorValue[] = new ZString( $payload['message'] );
450                break;
451
452            case ZErrorTypeRegistry::Z_ERROR_USER_CANNOT_RUN:
453                // No context.
454                break;
455
456            case ZErrorTypeRegistry::Z_ERROR_ARGUMENT_TYPE_MISMATCH:
457                $zErrorValue[] = new ZReference( $payload['expected'] );
458                $zErrorValue[] = new ZReference( $payload['actual'] );
459                $zErrorValue[] = new ZQuote( $payload['argument'] );
460                break;
461
462            case ZErrorTypeRegistry::Z_ERROR_ARGUMENT_COUNT_MISMATCH:
463                $zErrorValue[] = new ZString( $payload['expected'] );
464                $zErrorValue[] = new ZString( $payload['actual'] );
465                $zErrorValue[] = ZObjectFactory::create( [ 'Z1', ...$payload['arguments'] ] );
466                break;
467
468            case ZErrorTypeRegistry::Z_ERROR_NOT_IMPLEMENTED_YET:
469                $zErrorValue[] = new ZString( $payload['data'] );
470                break;
471
472            case ZErrorTypeRegistry::Z_ERROR_INVALID_EVALUATION_RESULT:
473                $zErrorValue[] = new ZQuote( $payload['result'] );
474                break;
475
476            case ZErrorTypeRegistry::Z_ERROR_API_FAILURE:
477                $zErrorValue[] = new ZQuote( $payload['request'] );
478                $zErrorValue[] = $payload['error'];
479                break;
480
481            case ZErrorTypeRegistry::Z_ERROR_OBJECT_TYPE_MISMATCH:
482                $zErrorValue[] = new ZReference( $payload['expected'] );
483                $zErrorValue[] = new ZQuote( $payload['actual'] );
484                break;
485
486            case ZErrorTypeRegistry::Z_ERROR_CONNECTION_FAILURE:
487                $zErrorValue[] = new ZString( $payload['host'] );
488                break;
489
490            case ZErrorTypeRegistry::Z_ERROR_DUPLICATE_LANGUAGES:
491                $zErrorValue[] = new ZString( $payload['language'] );
492                break;
493
494            case ZErrorTypeRegistry::Z_ERROR_INVALID_ORCHESTRATOR_RESULT:
495                $zErrorValue[] = new ZQuote( $payload['request'] );
496                $zErrorValue[] = new ZQuote( $payload['response'] );
497                break;
498
499            default:
500                break;
501        }
502
503        return new ZError(
504            new ZReference( $zErrorType ),
505            self::createTypedError( $zErrorType, $zErrorValue )
506        );
507    }
508
509    /**
510     * Create a ZTypedError instance given a errorType Zid and a set of values.
511     *
512     * @param string $errorType
513     * @param ZObject[] $errorValues
514     * @return ZTypedError
515     */
516    private static function createTypedError( $errorType, $errorValues ) {
517        return new ZTypedError( ZTypedError::buildType( $errorType ), $errorValues );
518    }
519
520    /**
521     * Create an unknown validation error
522     *
523     * @param string $message
524     * @return ZError
525     */
526    public static function createUnknownValidationError( $message ): ZError {
527        $zError = self::createZErrorInstance(
528            ZErrorTypeRegistry::Z_ERROR_UNKNOWN,
529            [ 'message' => $message ]
530        );
531        return self::createValidationZError( $zError );
532    }
533
534    /**
535     * Create Z507/Evaluation Error wrapping a Z500/Generic Error that
536     * wraps a string error message.
537     *
538     * @param string|ZObject $message The non-error to wrap.
539     * @param string $call The functional call context.
540     * @return ZError
541     */
542    public static function createEvaluationError( $message, $call ): ZError {
543        $wrappedError = self::createZErrorInstance(
544            ZErrorTypeRegistry::Z_ERROR_UNKNOWN, [ 'message' => $message ]
545        );
546        $zerror = self::createZErrorInstance(
547            ZErrorTypeRegistry::Z_ERROR_EVALUATION,
548            [
549                'functionCall' => $call,
550                'error' => $wrappedError
551            ]
552        );
553        return $zerror;
554    }
555
556    /**
557     * Convenience method to create a ApiFailureError that propagates a given
558     * ZError or wraps a Z500 with a given message.
559     *
560     * @param string|ZError $error The error or message to wrap
561     * @param \stdClass|string $request The function call that generated an API error
562     * @return ZError
563     */
564    public static function createApiFailureError( $error, $request ): ZError {
565        $wrappedError = ( $error instanceof ZError ) ? $error :
566            self::createZErrorInstance( ZErrorTypeRegistry::Z_ERROR_UNKNOWN, [ 'message' => $error ] );
567        return self::createZErrorInstance(
568            ZErrorTypeRegistry::Z_ERROR_API_FAILURE, [
569                'request' => $request,
570                'error' => $wrappedError
571            ]
572        );
573    }
574}