esbenp / esbenp/heimdal

config:cache command crashes with add_context closure

Open
#33 0 comments 0 reactions 0 assignees View on GitHub
Dominant language
PHP
Stars
122
Forks
39
PR merge metrics
No merged PRs in 30d

Description

Using add_context giving closure error
![Screenshot from 2021-09-01 15-57-45](https://user-images.githubusercontent.com/8122779/131656048-bef2c14b-f989-45a3-b849-8edd661e91b8.png)

```
'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];
}
],
```

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.