Merge pull request #9106 from JakubOnderka/sentry-nicer

chg: [sentry] Capture exception with message
pull/9476/head
Jakub Onderka 2024-01-04 15:57:24 +01:00 committed by GitHub
commit 58d89510a5
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
2 changed files with 15 additions and 7 deletions

View File

@ -3657,13 +3657,11 @@ class AppModel extends Model
{
// If Sentry is installed, send exception to Sentry
if (function_exists('\Sentry\captureException') && $type === LOG_ERR) {
\Sentry\captureException($exception);
\Sentry\captureException(new Exception($message, $type, $exception));
}
$message .= "\n";
do {
$message .= sprintf("[%s] %s", get_class($exception), $exception->getMessage());
$message .= sprintf("\n[%s] %s", get_class($exception), $exception->getMessage());
$message .= "\nStack Trace:\n" . $exception->getTraceAsString();
$exception = $exception->getPrevious();
} while ($exception !== null);

View File

@ -255,7 +255,7 @@ class AttachmentScan extends AppModel
}
$scanned++;
} catch (NotFoundException $e) {
// skip
// skip if file doesn't exists
} catch (Exception $e) {
$this->logException("Could not scan attachment for $type {$attribute['Attribute']['id']}", $e);
$fails++;
@ -341,7 +341,17 @@ class AttachmentScan extends AppModel
$file = $this->attachmentTool()->getShadowFile($attribute['event_id'], $attribute['id']);
}
if (in_array('attachment', $moduleInfo['types'])) {
if (in_array('attachment', $moduleInfo['types'], true)) {
$fileSize = $file->size();
if ($fileSize === false) {
throw new Exception("Could not read size of file '$file->path'.");
}
if ($fileSize === 0) {
return false; // empty file is automatically considered as not infected
}
/* if ($file->size() > 50 * 1024 * 1024) {
$this->log("File '$file->path' is bigger than 50 MB, will be not scanned.", LOG_NOTICE);
return false;
@ -349,7 +359,7 @@ class AttachmentScan extends AppModel
$fileContent = $file->read();
if ($fileContent === false) {
throw new Exception("Could not read content of file '$file->path'.");
throw new Exception("Could not read content of file '$file->path'.");
}
$attribute['data'] = base64_encode($fileContent);
} else {