Creates a new validation error object and adds it to $this->errors

@param string $message The error message
@param integer $code The error code (a unix timestamp)
@param array $arguments Arguments to be replaced in message
@return void
@api
770775
protected function addError($message, $code, array $arguments = [])
    {
        $this->result->addError(new ValidationError($message, $code, $arguments));
    }
902130
public function sendError($code = 204, $vars = null)
    {
        static $errors = [];

        if (empty($errors)) {
            $errors = require(str_replace('Cli', 'Config', __DIR__) . DIRECTORY_SEPARATOR . 'Errors.php');
        }

        if (isset($errors[ $code ])) {
            $languageKey = $errors[ $code ];
        }

        $languageKey = strtoupper($code . '_' . $languageKey);

        $error = [
            'code'    => $code,
            'title'   => language()->getLine($languageKey . '_TITLE'),
            'message' => language()->getLine($languageKey . '_MESSAGE'),
        ];

        $this->statusCode = $code;
        $this->reasonPhrase = $error[ 'title' ];

        if (is_string($vars)) {
            $error[ 'message' ] = $vars;
        } elseif (is_array($vars)) {
            $error = array_merge($error, $vars);
        }

        $this->write(
            (new Format())
                ->setContextualClass(Format::DANGER)
                ->setString($error[ 'code' ] . ' - ' . $error[ 'title' ])
                ->setNewLinesAfter(1)
        );

        $this->write(
            (new Format())
                ->setString($error[ 'message' ])
                ->setNewLinesAfter(1)
        );

        exit(EXIT_ERROR);
    }
137178
private function addError(string $msg, ?string $field = null): void
    {
        if (!$field) {
            $field = 'all';
        }

        if (!($this->errors[$field] ?? [])) {
            $this->errors[$field] = [];
        }

        $this->errors[$field][] = $msg;
    }
834838
public function addError($message, ...$args)
    {
        $message = $this->translate($message);
        if (!empty($args)) $message = vsprintf($message, $args);
        
        $this->errors[] = $message;
    }
763554
public static function errorToException($code, $message, $file, $line)
    {
        if (error_reporting() & $code) {
            throw new \ErrorException($message, 0, $code, $file, $line);
        }
    }
84657
public function setError($code, $message = '', Exception $innerException = null)
    {
        if ($code == static::ERR_NONE && !$message && $innerException === null) {
            $this->errorCode = static::ERR_NONE;
            $this->errorMessage = '';
            $this->innerException = null;
        } else {
            $code = (int) $code;
            $this->errorCode = $code === static::ERR_NONE ? static::ERR_OTHER : $code;
            $message = trim((string) $message);
            if ($message === '') {
                switch ($this->errorCode) {
                    case static::ERR_NOCURRENTLIBRARY:
                        $this->errorMessage = t("There's no current geolocation library");
                        break;
                    case static::ERR_NOCURRENTIPADDRESS:
                        $this->errorMessage = t('The IP address of the current client is not available');
                        break;
                    case static::ERR_IPNOTPUBLIC:
                        $this->errorMessage = t('The IP address is not in the public IP address ranges');
                        break;
                    case static::ERR_MISCONFIGURED:
                        $this->errorMessage = t('The geolocation library is misconfigured');
                        break;
                    case static::ERR_NETWORK:
                        $this->errorMessage = t('A network error occurred during the geolocalization');
                        break;
                    case static::ERR_LIBRARYSPECIFIC:
                        $this->errorMessage = t('An unspecified error occurred in the geolocation library');
                        break;
                    default:
                        $this->errorMessage = t('An unexpected error occurred in the geolocation library');
                }
            } else {
                $this->errorMessage = $message;
            }
            $this->innerException = $innerException;
        }
    }
1166540
public function error($label, $arguments = [])
    {
        $log_message = 'Error code: ' . $label;
        if ($arguments) {
            $log_message .= ', arguments: ' . json_encode($arguments);
        }
        Log::info($log_message);

        if($this->isAjaxRequest()) {
            $error_object = [
                'id' => 'server',
                'code' => '500',
                'message' => $label,
                'arguments' => $arguments
            ];

            echo json_encode([
                'errors' => [$error_object],
            ]);
        } else {
            echo "<h2>Server error: {$label}</h2>";
        }

        exit;
    }
1034484
public function setErrorString($code, $message)
    {
        if (!$this->isTranslatableStringValueValid($message)) {
            throw new InvalidArgumentException('Invalid translatable string value provided for Validator');
        }

        $this->translatable_errors[$code] = $message;
    }
194653
public function setError(?string $message = null) : void
    {
        $this->is_valid = false;
        $this->error = (null === $message) ? $this->default_error : $message;
    }
768022
protected function validateArgs(): void
    {
        if (! $this->rules) {
            return;
        }

        $validator = validator(
            $this->args,
            $this->rules,
            $this->messages,
            [
                'root' => $this->root,
                'context' => $this->context,
                // This makes it so that we get an instance of our own Validator class
                'resolveInfo' => $this->resolveInfo,
            ]
        );

        if ($validator->fails()) {
            foreach ($validator->errors()->getMessages() as $key => $errorMessages) {
                foreach ($errorMessages as $errorMessage) {
                    $this->validationErrorBuffer->push($errorMessage, $key);
                }
            }
        }

        $path = implode(
            '.',
            $this->resolveInfo()->path
        );
        $this->validationErrorBuffer->flush(
            "Validation failed for the field [$path]."
        );

        // reset rules and messages
        $this->rules = [];
        $this->messages = [];
    }
1336874
public static function error($message)
    {
        Craft::$app->controller->stdout($message.PHP_EOL, Console::FG_RED);
    }
299131
public function add($key, $message)
    {
        if (! isset($this->errors[$key])) $this->errors[$key] = [];
        $this->errors[$key][] = $message;
    }
113490
public function errorHandler($code, $message, $file, $line)
    {
        $this->debug->setShowBackTrace(false);
        $this->debug->onUncaughtException(new \ErrorException($message, $code, 0, $file, $line));
    }
454095
public function errors(array $errors, $code = 0)
    {
        foreach ($errors as $error) {
            $this->error($error, $code);
        }
    }
942642
public function handleErrors($code, $message, $file, $line)
    {
        throw new ErrorException($message, 0, $code, $file, $line);
    }
390193
public function errors(int $statusCode, string $message, $errors = null): void
    {
        $this->setStatusCode($statusCode);
        $this->setMessage($message);
        $this->setErrors($errors);

        throw new ApiException($this);
    }
670503
public function callErrorTrait($message, int $code, ?Exception $previous, $thrower): void
    {
        $message = $this->createMessage($message, $code);
        /** @noinspection PhpUndefinedMethodInspection */
        /** @noinspection PhpUndefinedClassInspection */
        parent::__construct($message, $code, $previous);
        $this->truncateTrace($thrower);
    }