decord/source/modules/errors/native/SentryInitUtils.tsx
github-actions da5b5e5efe chore: update source for alpha 346.6
Skipped 1 file(s) >100MB (GitHub limit): source/__polyfill/04xxx/module_4821.js (118.4 MB)
2026-09-12 13:45:10 +00:00

678 lines
21 KiB
TypeScript

// Module ID: 1233
// Function ID: 1234
// Name: SentryInitUtils
// Dependencies: [5, 17, 1074, 1085, 675, 3, 1234, 1100, 1242, 14168, 7704, 7709, 1358, 1232, 1364, 7705, 1150, 4615, 1608, 1359, 1345, 2]
// Exports: initSentry
// Module 1233 (SentryInitUtils)
import LoggerDefault from "Logger" /* 3 */;
import router_utils from "router_utils" /* 1100 */;
import SentryUtilsDefault from "SentryUtils" /* 1232 */;
import TelemetryRingLifecycle from "TelemetryRingLifecycle" /* 1234 */;
import AnalyticsUtilsDefault from "AnalyticsUtils" /* 1242 */;
import ClientInfoUtilsAll from "ClientInfoUtils" /* 1364 */;
import MetricEvents from "MetricEvents" /* 7709 */;
import asyncGeneratorStep from "asyncGeneratorStep" /* 5 */;
const require = globalThis.__r;
require = fn;
let closure_15 = async function _maybeBackfillMissingBreadcrumbsFromTelemetryRing(arg0) {
let breadcrumbs = arg0;
c2 = 0;
c3 = 0;
return (async (arg0, value) => {
if (c3 === 2) {
c3 = 3;
throw new TypeError("Generator functions may not be called on executing generators");
} else if (tmp4 === 3) {
if (arg0 === 1) {
throw value;
} else if (arg0 === 2) {
const obj2 = { value, done: true };
return obj2;
} else {
return { value: "HermesInternal", done: null };
}
} else {
try {
c3 = 2;
if (0 === c2) {
if (arg0 === 1) {
c3 = 3;
throw value;
} else if (arg0 === 2) {
c3 = 3;
const obj3 = { value, done: true };
return obj3;
} else {
closure_1 = tmp2;
closure_129_0 = breadcrumbs;
closure_129_1 = undefined;
breadcrumbs = breadcrumbs.breadcrumbs;
const _Array2 = Array;
if (Array.isArray(breadcrumbs)) {
if (breadcrumbs.length > 0) {
c3 = 3;
}
}
const SentryTelemetry = TelemetryRingLifecycle.SentryTelemetry;
items = [SentryTelemetry.snapshotForBreadcrumbs(), ];
const promise = new Promise((arg0, arg1) => {
closure_0 = arg1;
return setTimeout(() => {
const error = new Error("TelemetryRing breadcrumb timeout");
return closure_0(error);
}, 200);
});
items[1] = promise;
c2 = 1;
c3 = 1;
const obj4 = { value: Promise.race(items).catch(() => null), done: false };
return obj4;
}
} else if (arg0 === 1) {
c3 = 3;
throw value;
} else if (arg0 !== 2) {
closure_129_1 = value;
let isArray = null != closure_129_1;
if (isArray) {
const _Array = Array;
isArray = Array.isArray(closure_129_1.entries);
}
if (isArray) {
isArray = 0 !== closure_129_1.entries.length;
}
if (isArray) {
const entries = closure_129_1.entries;
closure_129_0.breadcrumbs = entries.map((data) => {
let key = data.message;
if (key == null) {
key = data.key;
}
return { message: key, category: "telemetry_ring", timestamp: data.timestamp / 1000, data: data.data };
});
}
}
c3 = 3;
const obj = { value, done: true };
return obj;
} catch (tmp21) {
c3 = tmp;
throw tmp21;
}
}
})();
};
function filterError(event_id, originalException) {
let message = event_id;
importDefault = originalException;
originalException = undefined;
if (originalException != null) {
originalException = originalException.originalException;
}
let status;
if (originalException != null) {
status = originalException.status;
}
if (!status) {
let captchaFields;
if (originalException != null) {
captchaFields = originalException.captchaFields;
}
let tmp4 = null;
if (null != captchaFields) {
let code;
if (originalException != null) {
code = originalException.code;
}
tmp4 = code;
}
let flag = false;
if (tmp4) {
flag = false;
if (tmp4 < 0) {
flag = true;
}
}
} else {
flag = true;
}
if (!flag) {
let originalException1;
if (originalException != null) {
originalException1 = originalException.originalException;
}
let code1;
if (originalException1 != null) {
if (originalException1.err != null) {
code1 = err.code;
}
}
let flag2 = false;
if ("ABORTED" === code1) {
flag2 = true;
}
flag = flag2;
}
if (!flag) {
let originalException2;
if (originalException != null) {
originalException2 = originalException.originalException;
}
message = undefined;
if (originalException2 != null) {
message = originalException2.message;
}
let someResult = typeof message === "string";
if (typeof message === "string") {
someResult = closure_11.some((item) => message.includes(item));
}
flag = someResult;
}
if (flag) {
event_id = event_id.event_id;
let tmp20 = typeof event_id === "string";
if (typeof event_id === "string") {
tmp20 = 0 !== event_id.length;
}
if (tmp20) {
SentryUtilsDefault.markCrashHandled(event_id);
}
} else {
let originalException3;
if (originalException != null) {
originalException3 = originalException.originalException;
}
let status1;
if (originalException3 != null) {
status1 = originalException3.status;
}
if (null != status1) {
if (null == event_id.tags) {
event_id.tags = {};
}
event_id.tags.httpStatusCode = status1;
}
if (!c14) {
if (closure_20()) {
const _Math = Math;
}
trackCrash(event_id, originalException, false);
}
return (async (arg0, value) => {
closure_1 = tmp3;
const ZoomedInTelemetry = tmp3(c3[6]).ZoomedInTelemetry;
items = [ZoomedInTelemetry.flushNow(), ];
items[1] = new Promise((arg0) => setTimeout(arg0, 200));
await Promise.race(items);
if (1 === tmp7) {
c2 = 0;
trackCrash(closure_129_0, closure_129_1);
c4 = 3;
} else if (2 === tmp7) {
if (arg0 === 1) {
c4 = 3;
throw value;
} else if (arg0 === 2) {
c2 = 0;
c4 = 3;
return { value, done: true };
} else {
c3 = 3;
c4 = 1;
return {
value: (function maybeBackfillMissingBreadcrumbsFromTelemetryRing() {
const self = this;
const apply = closure_1_15.apply;
if (typeof apply === "unknown") {
let applyArgumentsResult = HermesBuiltin.applyArguments(self);
} else {
applyArgumentsResult = apply(self, arguments);
}
return applyArgumentsResult;
})(closure_129_0),
done: false
};
}
} else if (arg0 === 1) {
c4 = 3;
throw value;
} else if (arg0 !== 2) {
c2 = 0;
}
return value;
})();
}
return null;
}
function getCrashErrorMessage(exception) {
exception = exception.exception;
let first;
if (exception != null) {
const values = exception.values;
if (values != null) {
first = values[0];
}
}
if (null == first) {
const extra2 = exception.extra;
let prop;
if (extra2 != null) {
prop = extra2.persisted_error_message;
}
let message1;
if (typeof prop === "string") {
if (prop.length > 0) {
message1 = prop;
}
}
if (message1 == null) {
message1 = exception.message;
}
return message1;
} else {
({ type, value } = first);
if (null != type) {
if (null != value) {
const _HermesInternal = HermesInternal;
return "" + type + ": " + value;
}
}
const extra = exception.extra;
if (extra != null) {
const prop1 = extra.persisted_error_message;
}
let message = type;
if (type == null) {
message = value;
}
if (message == null) {
message = exception.message;
}
if (message == null) {
let tmp2;
if (typeof prop1 === "string") {
if (prop1.length > 0) {
tmp2 = prop1;
}
}
message = tmp2;
}
return message;
}
}
function getErrorStackTrace(exception) {
exception = exception.exception;
let first;
if (exception != null) {
const values = exception.values;
if (values != null) {
first = values[0];
}
}
if (null == first) {
const extra2 = exception.extra;
let prop;
if (extra2 != null) {
prop = extra2.persisted_error_stack;
}
let tmp6;
if (typeof prop === "string") {
if (prop.length > 0) {
tmp6 = prop;
}
}
return tmp6;
} else {
const stacktrace = first.stacktrace;
let joined;
if (stacktrace != null) {
const frames = stacktrace.frames;
if (frames != null) {
const mapped = frames.map((filename) => "" + filename.filename + ":" + filename.lineno + ":" + filename.colno);
joined = mapped.join("\n");
}
}
if (null != joined) {
if (joined.length > 0) {
return joined;
}
}
const extra = exception.extra;
let prop1;
if (extra != null) {
prop1 = extra.persisted_error_stack;
}
let tmp4;
if (typeof prop1 === "string") {
if (prop1.length > 0) {
tmp4 = prop1;
}
}
return tmp4;
}
}
function trackCrash(event, hint, arg2) {
let flag = arg2;
if (arg2 === undefined) {
flag = true;
}
logger.info("Crash", { event, hint });
({ level, extra } = event);
let native_is_native;
if (extra != null) {
native_is_native = extra.native_is_native;
}
if (null != native_is_native) {
let tmp4 = "true" === event.extra.native_is_native;
} else {
const tags = event.tags;
let prop;
if (tags != null) {
prop = tags["event.origin"];
}
tmp4 = "javascript" !== prop;
}
if ("fatal" !== level) {
return event;
}
let tmp5 = tmp4;
if (!tmp4) {
tmp5 = "error" !== level;
}
let num = 1;
if (!tmp5) {
num = 0.01;
}
if (!c14) {
const _Math = Math;
if (Math.random() > num) {
const event_id = event.event_id;
let tmp7 = typeof event_id === "string";
if (typeof event_id === "string") {
tmp7 = 0 !== event_id.length;
}
if (tmp7) {
SentryUtilsDefault.markCrashHandled(event_id);
}
}
}
let tmp13 = null;
if (flag) {
let event_id1 = event.event_id;
if (event_id1 == null) {
event_id1 = null;
}
tmp13 = event_id1;
}
const timestamp = event.timestamp;
let result;
if (null != timestamp) {
if (typeof timestamp === "number") {
const _isNaN = isNaN;
if (!isNaN(timestamp)) {
result = 1000 * timestamp;
}
}
const _Date = Date;
if (timestamp instanceof Date) {
result = timestamp.getTime();
} else if (typeof timestamp === "string") {
const _Date3 = Date;
const parsed = Date.parse(timestamp);
const _Number = Number;
if (!Number.isNaN(parsed)) {
result = parsed;
}
}
}
if (result == null) {
const _Date2 = Date;
result = Date.now();
}
const obj = { event, hint };
const obj3 = router_utils;
const track = AnalyticsUtilsDefault.track;
if (tmp4) {
let extra1 = event.extra;
if (extra1 == null) {
extra1 = {};
}
const obj4 = { did_crash: true, sentry_issue_id: tmp13, client_track_timestamp: result, exit_reason: null, exit_description: null, tombstone_hash: null, tombstone_cause: null, tombstone: null, call_stack_tree: null, binary_name: null, exception_message: null, exception_stacktrace: null, js_error_message: null, js_error_stacktrace: null };
const native_exit_reason = extra1.native_exit_reason;
let tmp27 = null;
if (typeof native_exit_reason === "string") {
tmp27 = null;
if (native_exit_reason.length > 0) {
tmp27 = native_exit_reason;
}
}
obj4.exit_reason = tmp27;
const prop1 = extra1.native_exit_description;
let tmp28 = null;
if (typeof prop1 === "string") {
tmp28 = null;
if (prop1.length > 0) {
tmp28 = prop1;
}
}
obj4.exit_description = tmp28;
const prop2 = extra1.native_tombstone_hash;
let tmp29 = null;
if (typeof prop2 === "string") {
tmp29 = null;
if (prop2.length > 0) {
tmp29 = prop2;
}
}
obj4.tombstone_hash = tmp29;
const prop3 = extra1.native_tombstone_cause;
let tmp30 = null;
if (typeof prop3 === "string") {
tmp30 = null;
if (prop3.length > 0) {
tmp30 = prop3;
}
}
obj4.tombstone_cause = tmp30;
const native_tombstone = extra1.native_tombstone;
let tmp31 = null;
if (typeof native_tombstone === "string") {
tmp31 = null;
if (native_tombstone.length > 0) {
tmp31 = native_tombstone;
}
}
obj4.tombstone = tmp31;
const prop4 = extra1.native_tombstone_group_by;
let tmp32 = null;
if (typeof prop4 === "string") {
tmp32 = null;
if (prop4.length > 0) {
tmp32 = prop4;
}
}
obj4.call_stack_tree = tmp32;
const prop5 = extra1.native_tombstone_origin;
let tmp33 = null;
if (typeof prop5 === "string") {
tmp33 = null;
if (prop5.length > 0) {
tmp33 = prop5;
}
}
obj4.binary_name = tmp33;
obj4.exception_message = getCrashErrorMessage(event);
obj4.exception_stacktrace = getErrorStackTrace(event);
const prop6 = extra1.persisted_error_message;
let tmp36 = null;
if (typeof prop6 === "string") {
tmp36 = null;
if (prop6.length > 0) {
tmp36 = prop6;
}
}
obj4.js_error_message = tmp36;
const prop7 = extra1.persisted_error_stack;
let tmp37 = null;
if (typeof prop7 === "string") {
tmp37 = null;
if (prop7.length > 0) {
tmp37 = prop7;
}
}
obj4.js_error_stacktrace = tmp37;
track(tmp20.APP_NATIVE_CRASH, obj4);
let tmp25 = tmp18;
let tmp26 = tmp18;
} else {
const obj5 = { path: obj3.getHistory().location.pathname, client_track_timestamp: result, sentry_issue_id: tmp13, extra: hint, error_message: getCrashErrorMessage(event), error_level: level, error_stack: getErrorStackTrace(event) };
track(tmp20.APP_CRASHED, obj5);
tmp25 = tmp18;
tmp26 = tmp18;
}
const event_id2 = event.event_id;
let tmp39 = typeof event_id2 === "string";
if (typeof event_id2 === "string") {
tmp39 = 0 !== event_id2.length;
}
if (tmp39) {
tmp25(1232).markCrashHandled(event_id2);
const tmp25Result = tmp25(1232);
}
const AppCrashedReasons = tmp11(14168).AppCrashedReasons;
const tmp41 = tmp4 ? AppCrashedReasons.UNHANDLED_NATIVE_ERROR : AppCrashedReasons.UNHANDLED_JS_ERROR;
const obj6 = { name: MetricEvents.MetricEvents.APP_CRASHED, tags: null };
items = ["reason:" + tmp41, ];
if (level == null) {
level = "unknown";
}
items[1] = "level:" + level;
obj6.tags = items;
tmp26(7704).increment(obj6, true);
}
const NativeModules = fn(17).NativeModules;
const Constants = fn(1074);
({ AnalyticEvents: metroRequire, Endpoints } = Constants);
const PRIMARY_DOMAIN = fn(1085).PRIMARY_DOMAIN;
let registerSpanErrorInstrumentation = fn(675);
registerSpanErrorInstrumentation = registerSpanErrorInstrumentation.reactNavigationIntegration();
const regExp = new RegExp("/v" + window.GLOBAL_ENV.API_VERSION + Endpoints.METRICS, "g");
let items = [regExp, , ];
const regExp1 = new RegExp("/v" + window.GLOBAL_ENV.API_VERSION + Endpoints.METRICS_V2, "g");
items[1] = regExp1;
const regExp2 = new RegExp("/v" + window.GLOBAL_ENV.API_VERSION + Endpoints.TRACK, "g");
items[2] = regExp2;
const logger = new LoggerDefault("Sentry");
let closure_11 = ["The operation couldn\u2019t be completed. (com.apple.CallKit.error.requesttransaction", "Request has been terminated", "couldn't execute statement: database is disabled", "couldn't delete database: database is currently open", "database is no longer open"];
let c12 = 0.05;
let c13 = 0.005;
let c14 = false;
const CommonSentryInitUtils = fn(1358);
let closure_20 = CommonSentryInitUtils.filterThrottle({ maxBudgetMinute: 1, maxBudgetHour: 15 });
const size = fn(2);
const result1 = size.fileFinishedImporting("modules/errors/native/SentryInitUtils.tsx");
export const routingInstrumentation = registerSpanErrorInstrumentation;
export const initSentry = function initSentry() {
const CrashReportingManager = NativeModules.CrashReportingManager;
if (CrashReportingManager != null) {
const isUserStaffForCrashReporting = CrashReportingManager.getIsUserStaffForCrashReporting((arg0) => {
closure_14 = arg0;
constants = ClientInfoUtilsAll.getConstants();
const ReleaseChannel = constants.ReleaseChannel;
if (-1 === ReleaseChannel.indexOf("debug")) {
if (-1 === ReleaseChannel.indexOf("developer")) {
const isStable = require("ReleaseChannelUtils").isStable;
const obj2 = { releaseChannel: ReleaseChannel, isProductionChannel: isStable };
logger.verbose("Initialize", obj2);
if (obj15.isAndroid()) {
if (isStable) {
const device = tmp14(tmp[17]).getDevice();
const tmp14Result = tmp14(tmp[17]);
}
}
c12 = 0.05;
const SentryDsn = constants.SentryDsn;
if (isStable) {
let SentryStaffDsn = SentryDsn;
if (tmp14Result9.isMetaQuest()) {
c12 = 1;
c13 = 1;
SentryStaffDsn = SentryDsn;
}
tmp14Result9 = tmp14(tmp[18]);
} else {
c12 = 1;
SentryStaffDsn = constants.SentryAlphaBetaDsn;
}
if (arg0) {
SentryStaffDsn = constants.SentryStaffDsn;
c12 = 1;
}
obj15 = require("PlatformUtils");
const lastCrashReport = require("SentryUtils").getLastCrashReport();
const obj4 = require("SentryUtils");
lastCrashReport.then((result) => {
if (null != result) {
closure_1_19(result, { crash_event_source: "startup_reconcile" });
}
}).catch((error) => {
logger.warn("Failed to replay pending crash report", error);
});
const nextPromise = lastCrashReport.then((result) => {
if (null != result) {
closure_1_19(result, { crash_event_source: "startup_reconcile" });
}
});
const tmp14Result10 = require("module_675");
let str2 = "ios";
if (tmp14Result11.isAndroid()) {
str2 = "android";
}
const obj3 = { tunnel: `/error-reporting-proxy/${str2}`, autoInitializeNativeSdk: false, beforeSend, dist: "6411", dsn: SentryStaffDsn, environment: ReleaseChannel, tracesSampleRate: 0, sampleRate: 1, ignoreErrors, release: "discord_android@346.6.0-2+346206", tracePropagationTargets: null, integrations: null, beforeBreadcrumb: null };
items = [PRIMARY_DOMAIN];
obj3.tracePropagationTargets = items;
const items1 = [registerSpanErrorInstrumentation, , ];
tmp14Result11 = require("PlatformUtils");
items1[1] = require("module_675").featureFlagsIntegration();
const tmp14Result12 = require("module_675");
const obj5 = {
shouldCreateSpanForRequest(arg0) {
closure_0 = arg0;
return !closure_1_9.some((item) => null != closure_0.match(item));
}
};
items1[2] = require("module_675").reactNativeTracingIntegration(obj5);
obj3.integrations = items1;
obj3.beforeBreadcrumb = function beforeBreadcrumb(data) {
if (null == data.data) {
data.data = {};
}
const currentMemoryUsageKB = closure_1_1(dependencyMap[19]).getCurrentMemoryUsageKB();
if (null != currentMemoryUsageKB) {
data.data.client_performance_memory = currentMemoryUsageKB;
}
const obj = closure_1_1(dependencyMap[19]);
const currentCPUUsagePercent = closure_1_1(dependencyMap[19]).getCurrentCPUUsagePercent();
if (null != currentCPUUsagePercent) {
data.data.client_performance_cpu = currentCPUUsagePercent;
}
return data;
};
tmp14Result10.init(obj3);
const tmp14Result13 = require("module_675");
require("module_675").setTag("buildNumber", "6411");
const tmp14Result14 = require("module_675");
require("module_675").setTag("appVersion", constants.Version);
const tmp14Result15 = require("module_675");
const _HermesInternal = HermesInternal;
require("module_675").setTag("design_id", "" + require("DesignIds").DesignIds.DESIGN_TABS_IA);
const tmp14Result16 = require("module_675");
}
}
});
}
};