function sendError($error, stdClass $context)
{
if (is_string($error)) {
$error = new Exception($error);
}
try {
if ($this->onSendError !== null) {
$onSendError = $this->onSendError;
$e = call_user_func_array($onSendError, array(&$error, $context));
if ($e instanceof Exception || $e instanceof Throwable) {
$error = $e;
}
}
} catch (Exception $e) {
$error = $e;
}
$stream = new BytesIO();
$writer = new Writer($stream, true);
$stream->write(Tags::TagError);
$writer->writeString($this->debug ? $error->getTraceAsString() : $error->getMessage());
return $stream;
}