Closed phyzical closed 4 years ago
Notes: Reporter was using 3.0.0-beta1
update 3.0.0-beta2 "runs" But notices are throwing
[Emergency] Uncaught InvalidArgumentException: The "notice" is not a valid enum value.
GET
Line 77 in vendor/sentry/sentry/src/Severity.php
Source
68
69 /**
70 * Constructor.
71 *
72 * @param string $value The value this instance represents
73 */
74 public function __construct(string $value = self::INFO)
75 {
76 if (!\in_array($value, self::ALLOWED_SEVERITIES, true)) {
77 throw new \InvalidArgumentException(sprintf('The "%s" is not a valid enum value.', $value));
78 }
79
80 $this->value = $value;
81 }
82
83 /**
Trace
Sentry\Severity->__construct(notice)
SentryHandler.php:73
PhpTek\Sentry\Handler\SentryHandler->write(Array)
AbstractProcessingHandler.php:39
Monolog\Handler\AbstractProcessingHandler->handle(Array)
Logger.php:344
Monolog\Logger->addRecord(250, E_NOTICE: Undefined variable: $b, Array)
Logger.php:609
Monolog\Logger->log(250, E_NOTICE: Undefined variable: $b, Array)
ErrorHandler.php:160
Monolog\ErrorHandler->handleError(8, Undefined variable: $b, utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
call_user_func(Array, 8, Undefined variable: $b, utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
ErrorHandler.php:173
Monolog\ErrorHandler->handleError(8, Undefined variable: $b, /utilities-ss4/code/helpers/SentryHelper.php, 65, Array)
SentryHelper.php:65
StrangeAnimals\Utilities\SentryHelper::testPHP()
Page.php:364```
public static function testPHP()
{
$a = ${'$b'};
}
This is basically a scenario I would never come across as I always run with error_reporting E_ALL
, meaning I attend-to these sorts of errors before they go to UAT or PROD and are subsequently reported to Sentry.
Not to say this isn't a legit issue - it is.
Something like the following should sort it:
/**
* Maps PHP's internal error-types into those suited to {@link Severity}.
*
* @param string $level The incoming level.
* @return string
*/
private static function process_level(string $level) : string
{
// PHP to Sentry\Severity map
$map = [
'error' => 'ERROR',
'warning' => 'WARNING',
'parse' => 'ERROR',
'notice' => 'INFO',
];
$defaultLevel = $map['error']; // It's an "ERROR" until proven otherwise.
$level = $level ?: $defaultLevel;
if (!isset($map[$level])) {
$level = $defaultLevel;
}
return strtolower($level);
}
Confirmed this as working atleast for my bug
via the above and $this->client->getSDK()->captureMessage($record['formatted'], new Severity(self::process_level($record['level_name'])));
@phyzical Please try with 3.0.0-beta3
works for me!