fix(sentry): resolve minified exception types on web release

This commit is contained in:
dab246
2026-03-03 11:43:45 +07:00
committed by Dat H. Pham
parent 2e8a11e7eb
commit 437c46f5ff
53 changed files with 133 additions and 109 deletions
+1 -1
View File
@@ -88,7 +88,7 @@ class MailAddress with EquatableMixin {
if (postChar == '.') {
var lastChar = address[pos - 1];
if (lastChar == '@' || lastChar == '.') {
throw const AddressException('Subdomain expected before "." or duplicate "." in "address"');
throw AddressException('Subdomain expected before "." or duplicate "." in "$address"');
}
domainSB.write('.');
pos++;
+6
View File
@@ -1,6 +1,7 @@
import 'package:core/utils/application_manager.dart';
import 'package:core/utils/build_utils.dart';
import 'package:core/utils/config/env_loader.dart';
import 'package:core/utils/app_logger.dart';
import 'package:flutter_dotenv/flutter_dotenv.dart';
/// Holds configuration values for initializing Sentry.
@@ -69,6 +70,11 @@ class SentryConfig {
final appVersion = await ApplicationManager().getAppVersion();
const sentryDist = String.fromEnvironment('SENTRY_DIST');
logTrace(
'SentryConfig::load: sentryDist is $sentryDist,'
'appVersion is $appVersion',
webConsoleEnabled: true,
);
return SentryConfig(
dsn: sentryDSN,
+39 -12
View File
@@ -55,27 +55,54 @@ class SentryInitializer {
SentryEvent event,
Hint? hint,
) async {
final req = event.request;
if (req == null) return event;
event.request = _sanitizeRequest(event.request);
event.exceptions = _deminifyExceptions(event.exceptions);
final sanitizedHeaders = Map<String, String>.from(req.headers)
..removeWhere(
(k, _) => _blockedHeaderPatterns.any(
(p) => k.toLowerCase().contains(p),
),
);
return event;
}
final sanitizedRequest = SentryRequest(
static SentryRequest? _sanitizeRequest(SentryRequest? req) {
if (req == null) return null;
return SentryRequest(
url: req.url,
method: req.method,
headers: sanitizedHeaders,
headers: _sanitizeHeaders(req.headers),
queryString: req.queryString,
cookies: null,
data: null,
);
}
event.request = sanitizedRequest;
static Map<String, String> _sanitizeHeaders(Map<String, String> headers) {
return Map<String, String>.from(headers)
..removeWhere(
(key, _) => _blockedHeaderPatterns.any(
(pattern) => key.toLowerCase().contains(pattern),
),
);
}
return event;
static List<SentryException>? _deminifyExceptions(
List<SentryException>? exceptions,
) {
if (exceptions == null) return null;
return exceptions.map((e) {
if (e.type?.startsWith('minified:') == true) {
final rawValue = e.value?.trim() ?? '';
final extractedType = RegExp(r'^([A-Za-z_][A-Za-z0-9_]*)\s*:')
.firstMatch(rawValue)
?.group(1) ??
RegExp(r"Instance of '([^']+)'").firstMatch(rawValue)?.group(1);
if (extractedType != null &&
extractedType.isNotEmpty &&
extractedType != 'minified' &&
!extractedType.startsWith('minified:')) {
e.type = extractedType;
}
}
return e;
}).toList();
}
}