Skip to content

Commit 905036c

Browse files
authored
Merge pull request #39 from flownative/task/align-captureMessage-signature
Align return type of `captureMessage` to `captureThrowable`
2 parents 459add1 + e48af45 commit 905036c

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
@@ -222,38 +222,28 @@ public function captureThrowable(Throwable $throwable, array $extraData = [], ar
222222
);
223223
}
224224

225-
public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): ?EventId
225+
public function captureMessage(string $message, Severity $severity, array $extraData = [], array $tags = []): CaptureResult
226226
{
227227
if (empty($this->dsn)) {
228-
if ($this->logger) {
229-
$this->logger->warning('Sentry: Failed capturing message, because no Sentry DSN was set. Please check your settings.');
230-
}
231-
return null;
232-
}
233-
234-
if (preg_match('/Sentry: [0-9a-f]{32}/', $message) === 1) {
235-
return null;
228+
return new CaptureResult(
229+
false,
230+
'Failed capturing message, because no Sentry DSN was set. Please check your settings.',
231+
''
232+
);
236233
}
237234

235+
$this->setTags();
238236
$this->configureScope($extraData, $tags);
239237
$eventHint = EventHint::fromArray([
240238
'stacktrace' => $this->prepareStacktrace()
241239
]);
242-
$this->setTags();
243-
$sentryEventId = \Sentry\captureMessage($message, $severity, $eventHint);
244-
245-
if ($this->logger) {
246-
$this->logger->log(
247-
(string)$severity,
248-
sprintf(
249-
'%s (Sentry: %s)',
250-
$message,
251-
$sentryEventId
252-
)
253-
);
254-
}
240+
$sentryEventId = SentrySdk::getCurrentHub()->captureMessage($message, $severity, $eventHint);
255241

256-
return $sentryEventId;
242+
return new CaptureResult(
243+
true,
244+
$message,
245+
(string)$sentryEventId
246+
);
257247
}
258248

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

0 commit comments

Comments
 (0)