captureMessage method
Future<SentryId>
captureMessage(
- String? message, {
- SentryLevel? level,
- String? template,
- List? params,
- Hint? hint,
- ScopeCallback? withScope,
Captures the message.
Implementation
Future<SentryId> captureMessage(
String? message, {
SentryLevel? level,
String? template,
List<dynamic>? params,
Hint? hint,
ScopeCallback? withScope,
}) async {
var sentryId = SentryId.empty();
if (!_isEnabled) {
_options.logger(
SentryLevel.warning,
"Instance is disabled and this 'captureMessage' call is a no-op.",
);
} else if (message == null) {
_options.logger(
SentryLevel.warning,
'captureMessage called with null parameter.',
);
} else {
final item = _peek();
late Scope scope;
final s = _cloneAndRunWithScope(item.scope, withScope);
if (s is Future<Scope>) {
scope = await s;
} else {
scope = s;
}
try {
sentryId = await item.client.captureMessage(
message,
level: level,
template: template,
params: params,
scope: scope,
hint: hint,
);
} catch (exception, stackTrace) {
_options.logger(
SentryLevel.error,
'Error while capturing message with id: $message',
exception: exception,
stackTrace: stackTrace,
);
if (_options.automatedTestMode) {
rethrow;
}
} finally {
_lastEventId = sentryId;
}
}
return sentryId;
}