Return a formatted error linked to pug source.

@param \Throwable $error
@param string     $code
@param string     $path

@throws \Throwable

@return LocatedException|\Throwable
5671
public function getDebugError($error, $code, $path = null)
    {
        /** @var \Throwable $error */
        $line = $this->getSourceLine($error);
        if ($line === false) {
            return $error;
        }
        $source = explode("\n", $code, max(2, $line));
        array_pop($source);
        $source = implode("\n", $source);
        $pos = mb_strrpos($source, 'PUG_DEBUG:');
        if ($pos === false) {
            throw $error;
        }
        $nodeId = intval(mb_substr($source, $pos + 10, 32));
        if (!$this->debugIdExists($nodeId)) {
            throw $error;
        }
        $node = $this->getNodeFromDebugId($nodeId);
        $nodeLocation = $node->getSourceLocation();
        $location = new SourceLocation(
            ($nodeLocation ? $nodeLocation->getPath() : null) ?: $path,
            $nodeLocation ? $nodeLocation->getLine() : 0,
            $nodeLocation ? $nodeLocation->getOffset() : 0,
            $nodeLocation ? $nodeLocation->getOffsetLength() : 0
        );
        $className = $this->getOption('located_exception_class_name');

        return new $className(
            $location,
            $error->getMessage(),
            $error->getCode(),
            $error
        );
    }
730650
public function setUnhandledError($code, $message = '')
    {
        $this->unhandledError = ($code == 0) ? false : true;
        $this->errorCode      = $code;
        $this->errorText      = $message;

        return $this;
    }
708073
public static function errorToException($code){
    if(!isset(self::$codeMap[$code])){
      return new BadResponseException(sprintf(
        'Undefined error code "%s"',
        $code
      ));
    }
    $exceptionClass = self::$codeMap[$code];
    return  new $exceptionClass;
  }
269426
public function error( $message, $code = null, $data = null )
    {
        if ( null === $code && isset( $this->errorCodes[$message] ) )
        {
            $code = $this->errorCodes[$message];
        }

        return $this->getResponse( 'error', (object) array(
            'code'      => $code,
            'message'   => $message,
            'data'      => $data,
        ) );
    }
224790
public static function get($code, $data=null) {
    self::predefine();
    if (defined($code)) {
      $def = unserialize(constant($code));
      $error = new ApplicationError($def[0], $def[1], $def[2], $def[3], $data);
      return $error;
    }
    else {
      throw new IllegalArgumentException("The error code '".$code."' is not defined");
    }
  }
104421
protected function createErrorResponse($content = 'Unknown Error', $code = 500)
    {
        $data = [
            'message' => $content
        ];

        $response = $this->createJsonResponse($data, $code);
        return $response;
    }
1029473
public function httpError($code)
    {
        switch ($code)
        {
            case 400:
                throw new Eresus_HTTP_Exception_BadRequest;
            case 401:
                throw new Eresus_HTTP_Exception_Unauthorized;
            case 402:
                throw new Eresus_HTTP_Exception_PaymentRequired;
            case 403:
                throw new Eresus_HTTP_Exception_Forbidden;
            case 404:
                throw new Eresus_HTTP_Exception_NotFound;
            default:
                throw new Eresus_HTTP_Exception('', $code);
        }
    }
763554
public static function errorToException($code, $message, $file, $line)
    {
        if (error_reporting() & $code) {
            throw new \ErrorException($message, 0, $code, $file, $line);
        }
    }
442143
protected function _error($message, $code)
    {
        header("HTTP/1.0 {$code} {$message}");
        echo $message;

        TableRegistry::get('Field.FieldInstances')->connection()->disconnect();
        exit(0);
    }
670989
protected function createErrorException($message, $code, $file, $line)
    {
        return new ErrorException($message, $code, 0/* will be resolved */, $file, $line);
    }
637643
protected function checkEval($code)
    {
        $error = error_get_last();
            
        if (isset($error['message']) 
			&& isset($error['line'])
			&& $error['message'] === 'parse error'
		) {
            $code = explode("\n", $code);
            $start = $error['line'] - 25;
            if ($start < 0) {
                $start = 0;
            }
            
            $code = array_splice($code, $start, 50);
            
            foreach ($code as $i => $line) {
                $code[$i] = (++$start) . ': ' . $line;
            }
            
            Exception::i(self::COMPILE_ERROR)
                ->setType('COMPILE')
                ->addVariable($error['message'])
                ->addVariable($error['line'])
                ->addVariable(implode("\n", $code))
                ->trigger();
        }
        
        return $this;
    }
197381
protected function throwError(/*# string */ $message, /*# int */ $code)
    {
        switch ($this->error_type) {
            case self::ERROR_WARNING:
                trigger_error($message, \E_USER_WARNING);
                break;
            case self::ERROR_EXCEPTION:
                throw new LogicException($message, $code);
            default:
                break;
        }
        return $this;
    }
892615
public static function to(?string $path = '/', ?int $code = null)
  {
    $redirect = new Redirect;
    $redirect->url = $path;

    if ($code !== null) {
      $redirect->code = $code;
      return $redirect->send();
    }

    return $redirect;
  }
778209
protected function getPregErrorText($code = null)
    {
        $code = $code ?: preg_last_error();

        if (!isset(self::$pregErrors[$code])) {
            $code = PREG_NO_ERROR;
        }

        return self::$pregErrors[$code];
    }
1355862
public static function forCompileError(array $error, $code, $limit = 25)
    {
        $code = explode("\n", $code);
        $start = $error['line'] - $limit;
        if ($start < 0) {
            $start = 0;
        }

        $code = array_splice($code, $start, $limit * 2);

        foreach ($code as $i => $line) {
            $code[$i] = (++$start) . ': ' . $line;
        }

        $message = sprintf(
            self::COMPILE_ERROR,
            $error['message'],
            $error['line'],
            implode("\n", $code)
        );

        return new static($message);
    }
106063
public function onError($code, $message, $file, $line)
    {
        $this->lastError = [
            'message' => $message,
            'file' => $file,
            'line' => $line
        ];

        $trace = debug_backtrace();
        if (count($trace) > 0 && !isset($trace[0]['file'])) {
            array_shift($trace);
        }

        switch ($code) {
            case E_NOTICE:
            case E_USER_NOTICE:
                $exc = new Errors\Notice($message, $trace);
                break;
            case E_WARNING:
            case E_USER_WARNING:
                $exc = new Errors\Warning($message, $trace);
                break;
            case E_ERROR:
            case E_CORE_ERROR:
            case E_RECOVERABLE_ERROR:
            case E_USER_ERROR:
                $exc = new Errors\Fatal($message, $trace);
                break;
            default:
                $exc = new Errors\Error($message, $trace);
                break;
        }
        $this->notifier->notify($exc);
        return false;
    }
312920
protected function buildLocatedError(
        \Throwable $originalException,
        array $nodes = [],
        array $path = []
    ): ExecutionException {
        return new ExecutionException(
            $originalException->getMessage(),
            $originalException instanceof GraphQLException
                ? $originalException->getNodes()
                : $nodes,
            $originalException instanceof GraphQLException
                ? $originalException->getSource()
                : null,
            $originalException instanceof GraphQLException
                ? $originalException->getPositions()
                : null,
            $originalException instanceof GraphQLException
                ? ($originalException->getPath() ?? $path)
                : $path,
            null,
            $originalException
        );
    }