Skip to content

Commit b9ae6f1

Browse files
committed
Align return type of captureMessage to captureThrowable
1 parent 0fd62e3 commit b9ae6f1

File tree

2 files changed

+19
-25
lines changed

2 files changed

+19
-25
lines changed

Classes/Command/SentryCommandController.php

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -77,7 +77,7 @@ public function testCommand(string $mode = self::TEST_MODE_THROW): void
7777

7878
private function captureMessage(): void
7979
{
80-
$eventId = $this->sentryClient->captureMessage(
80+
$captureResult = $this->sentryClient->captureMessage(
8181
'Flownative Sentry Plugin Test',
8282
Severity::debug(),
8383
[
@@ -86,7 +86,11 @@ private function captureMessage(): void
8686
);
8787

8888
$this->outputLine();
89-
$this->outputLine('<success>An informational message was sent to Sentry</success> Event ID: #%s', [$eventId]);
89+
if ($captureResult->suceess) {
90+
$this->outputLine('<success>An informational message was sent to Sentry</success> Event ID: #%s', [$captureResult->eventId]);
91+
} else {
92+
$this->outputLine('<error>Sending an informational message to Sentry failed</error>: %s', [$captureResult->message]);
93+
}
9094
$this->outputLine();
9195
}
9296

Classes/SentryClient.php

Lines changed: 13 additions & 23 deletions
Original file line numberDiff line numberDiff line change
@@ -209,38 +209,28 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
209209
);
210210
}
211211

212-
public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): ?EventId
212+
public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): CaptureResult
213213
{
214214
if (empty($this->dsn)) {
215-
if ($this->logger) {
216-
$this->logger->warning('Sentry: Failed capturing message, because no Sentry DSN was set. Please check your settings.');
217-
}
218-
return null;
219-
}
220-
221-
if (preg_match('/Sentry: [0-9a-f]{32}/', $message) === 1) {
222-
return null;
215+
return new CaptureResult(
216+
false,
217+
'Failed capturing message, because no Sentry DSN was set. Please check your settings.',
218+
''
219+
);
223220
}
224221

222+
$this->setTags();
225223
$this->configureScope($extraData, $tags);
226224
$eventHint = EventHint::fromArray([
227225
'stacktrace' => $this->prepareStacktrace()
228226
]);
229-
$this->setTags();
230-
$sentryEventId = \Sentry\captureMessage($message, $severity, $eventHint);
231-
232-
if ($this->logger) {
233-
$this->logger->log(
234-
(string)$severity,
235-
sprintf(
236-
'%s (Sentry: %s)',
237-
$message,
238-
$sentryEventId
239-
)
240-
);
241-
}
227+
$sentryEventId = SentrySdk::getCurrentHub()->captureMessage($message, $severity, $eventHint);
242228

243-
return $sentryEventId;
229+
return new CaptureResult(
230+
true,
231+
$message,
232+
(string)$sentryEventId
233+
);
244234
}
245235

246236
private function configureScope(array $extraData, array $tags): void

0 commit comments

Comments
 (0)