Skip to content

Commit

Permalink
Merge pull request #1069 from annuaire-entreprises-data-gouv-fr/TMP-f…
Browse files Browse the repository at this point in the history
…ix-error

Various sentry error fixes
  • Loading branch information
johangirod committed May 28, 2024
2 parents 0e7beb3 + 63ad8d0 commit 63f4f16
Show file tree
Hide file tree
Showing 6 changed files with 51 additions and 8 deletions.
4 changes: 2 additions & 2 deletions components-ui/icon/wrapper.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,7 @@ export const Icon: React.FC<PropsWithChildren<IProps>> = ({
console.error(`Error in <Icon/> : ${slug} icon does not exists`);
}
return (
<div id={id} className={styles.icon + ' ' + className}>
<span id={id} className={styles.icon + ' ' + className}>
<span
style={{
height: size + 'px',
Expand All @@ -39,6 +39,6 @@ export const Icon: React.FC<PropsWithChildren<IProps>> = ({
{icon}
</span>
<span>{children}</span>
</div>
</span>
);
};
4 changes: 2 additions & 2 deletions components-ui/information-tooltip/index.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -83,7 +83,7 @@ function InformationTooltip({
}}
>
<span>{children}</span>
<div
<span
className={`${style.tooltip} ${style[orientation]} ${
displayed ? style.displayed : ''
}`}
Expand All @@ -97,7 +97,7 @@ function InformationTooltip({
role="tooltip"
>
{label}
</div>
</span>
</span>
</>
);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -89,7 +89,7 @@ function ActesTable({ actes }: IActesTableProps) {
a.actes && (
<ul>
{(a?.actes || []).map((acteName) => (
<li>{acteName}</li>
<li key={acteName}>{acteName}</li>
))}
</ul>
),
Expand Down
4 changes: 2 additions & 2 deletions components/table/copy-paste.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -31,9 +31,9 @@ export function CopyPaste({
? children.replace(/\s/g, '')
: children;

if (navigator.clipboard) {
try {
navigator.clipboard.writeText(valueToCopy);
} else {
} catch {
const el = document.createElement('textarea');
el.value = valueToCopy;
document.body.appendChild(el);
Expand Down
2 changes: 1 addition & 1 deletion models/exceptions.ts
Original file line number Diff line number Diff line change
Expand Up @@ -33,7 +33,7 @@ export class Exception extends Error {
public context: IExceptionContext;
constructor({ name, message, cause, context }: IExceptionArgument) {
if (message == undefined && cause && 'name' in cause) {
message = cause.name;
message = cause.name !== 'Error' ? cause.name : cause.message;
}
super(message, { cause });
this.name = name;
Expand Down
43 changes: 43 additions & 0 deletions sentry.client.config.ts
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,7 @@ declare global {
IS_OUTDATED_BROWSER: boolean;
}
}

if (isNextJSSentryActivated) {
Sentry.init({
dsn: process.env.NEXT_PUBLIC_SENTRY_DSN,
Expand Down Expand Up @@ -37,6 +38,48 @@ if (isNextJSSentryActivated) {
];
}

if (
hint.originalException &&
typeof hint.originalException === 'object' &&
'message' in hint.originalException &&
typeof hint.originalException.message === 'string'
) {
/*
A LOT of hydration error happens in production. This can be due to a lot of reasons:
1. Browser code in client SSRed component
2. Bad nesting of HTML tags (e.g. <p> inside <span>)
3. User browser extension messing with the DOM
In any of these case, a unhandled exception is thrown and sentry catches it.
Only 1 and 2 are fixable. 3 is not. But real world data is not accurate enough to determine which is which.
For now, we rely on E2E tests to catch those.
In production, only the minified version of the error is sent to sentry.
These are the react error numbers that we want to ignore:
- [422](https://react.dev/errors/422)
- [423](https://react.dev/errors/423)
- [418](https://react.dev/errors/418)
- [425](https://react.dev/errors/425)
*/
if (
hint.originalException.message.match(
/Minified React error #(422|423|418|425)/
)
) {
event.fingerprint = ['React hydration error'];
}

/*
This is a common error that happens when a chunk fails to load. We want to group them together.
*/
if (
hint.originalException.message.match(/Loading chunk [\d]+ failed/)
) {
event.fingerprint = ['Chunk load error'];
}
}

if (!event.tags) {
event.tags = {};
}
Expand Down

0 comments on commit 63f4f16

Please sign in to comment.