ente/web/packages/utils/logging.ts
Manav Rathi 70cddfdf0b
[web] Remove Sentry
Sentry has a measurable impact on page load, a metric that I'm keen to
improve. Apparently by default it loses us 8-9 page speed points, though that
can be reduced to 3-4
(https://github.com/getsentry/sentry-javascript/issues/9179).

All of this is doable, but there are bigger tasks to deal with. This is not to
say that Sentry won't be useful again at some point, when we have time to deal
with it better. But right now, we discussed that it's just better to remove
Sentry instead of piling on to the sunk cost.
2024-03-12 13:24:33 +05:30

42 lines
1.6 KiB
TypeScript

/**
* Log an error
*
* The {@link message} property describes what went wrong. Generally (but not
* always) in such situations we also have an "error" object that has specific
* details about the issue - that gets passed as the second parameter.
*
* Note that the "error" {@link e} is not typed. This is because in JavaScript
* any arbitrary value can be thrown. So this function allows us to pass it an
* arbitrary value as the error, and will internally figure out how best to deal
* with it.
*
* Where and how this error gets logged is dependent on where this code is
* running. The default implementation logs a string to the console, but in
* practice the layers above us will use the hooks provided in this file to
* route and show this error elsewhere.
*
* TODO (MR): Currently this is a placeholder function to funnel error logs
* through. This needs to do what the existing logError in @ente/shared does,
* but it cannot have a direct Electron dependency here. For now, we just
* log on the console.
*/
export const logError = (message: string, e?: unknown) => {
if (e === undefined || e === null) {
console.error(message);
return;
}
let es: string;
if (e instanceof Error) {
// In practice, we expect ourselves to be called with Error objects, so
// this is the happy path so to say.
es = `${e.name}: ${e.message}\n${e.stack}`;
} else {
// For the rest rare cases, use the default string serialization of e.
es = String(e);
}
// TODO(MR): Use addLogLine
console.error(`${message}: ${es}`);
};