heimdal
heimdal copied to clipboard
config:cache command crashes with add_context closure
Using add_context giving closure error
'sentry_options' => [
'add_context' => function ($exception) {
$context['environment'] = app()->environment();
try {
$context['release'] = \Tremby\LaravelGitVersion\GitVersionHelper::getVersion();
} catch (\Tremby\LaravelGitVersion\Exception\CouldNotGetVersionException $exception) {
$context['release'] = '';
} catch (\Throwable $throwable) {
$context['release'] = '';
$context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
}
try {
$user = \User::current();
} catch (\Symfony\Component\HttpKernel\Exception\UnauthorizedHttpException $exception) {
$user = null;
} catch (\Throwable $throwable) {
$user = null;
$context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
}
if ($user) {
$context['user'] = [
'id' => $user->id,
'email' => $user->username,
];
} else {
$context['user'] = [];
}
// When running in console request is not available
if (substr(php_sapi_name(), 0, 3) !== 'cli') {
$request = app('request');
if (!isset($context['extra'])) {
$context['extra'] = [];
}
$context['extra']['request_data'] = json_encode($request->all());
try {
$context['extra']['api_version'] = app()->get("ApiVersion")->version();
} catch (\Throwable $throwable) {
$context['extra']['api_version'] = "unknown";
}
try {
$context['user']['ip_address'] = \Request::getClientIp();
} catch (\Symfony\Component\HttpFoundation\Exception\ConflictingHeadersException $exception) {
$context['user']['ip_address'] = '0.0.0.0';
} catch (\Throwable $throwable) {
$context['user']['ip_address'] = '0.0.0.0';
$context['extra']['exceptions_in_exception_handler'][] = (string) $throwable;
}
}
if (isset($context['extra']['exceptions_in_exception_handler'])) {
$context['tags']['exception'] = 'true';
}
return ['add_context' => $context];
}
],