Skip to content

feat(sveltekit): Add Sentry handlers to handle and handleError hooks #259

Merged
Lms24 merged 4 commits intolms/sveltekit-supportfrom
lms/just-ast-things-ii
Apr 21, 2023
Merged

feat(sveltekit): Add Sentry handlers to handle and handleError hooks #259
Lms24 merged 4 commits intolms/sveltekit-supportfrom
lms/just-ast-things-ii

Conversation

@Lms24
Copy link
Copy Markdown
Member

@Lms24 Lms24 commented Apr 21, 2023

This PR adds our handlers to the handle and handleError hooks in the SveltKit hooks files. I tested this with various cases of already existing, user-defined handlers.

One limtiation:
This currently only works for arrow function exports ( export const handleError = () => {}). The Kit docs examples always show that handlers should be exported with arrow functions but it is possible to add normal function exports (export function handleError(){}). In this case we just bail out and ask users to apply our handler manually. I believe this is a rather edge-casey scenario, so IMO it's fine to just bail at the moment.

#skip-changelog

ref #244

@Lms24 Lms24 requested review from AbhiPrasad and lforst April 21, 2023 10:07
@github-actions
Copy link
Copy Markdown

github-actions bot commented Apr 21, 2023

Messages
📖 Do not forget to update Sentry-docs with your feature once the pull request gets approved.

Generated by 🚫 dangerJS against 0a50651

@Lms24 Lms24 self-assigned this Apr 21, 2023
}
foundHandleError = true;
yellow(
'Cannot safely wrap an `export function handleError` declaration. Please wrap it manually with `handleErrorWithSentry`',
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why can't we wrap an export function handleError declaration?

Could we make the transform something like this?

export const handleError = Sentry.handleErrorWithSentry(function _handleError() {
  // ...
});

Little more complicated for Sentry.sentryHandle because of sequence, so I'm fine to log out a warning there.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We can, but I'm not sure if there are more problems involved if we convert a function export to an arrow function export. For instance the differences with this in the arrow vs normal functions?

Happy to take another look at this. Overall, I just want to avoid doing even more AST modification than we're currently doing. But your proposed transformation looks more reasonable to me than what I came up with before for this case😅

As for handle, I'm just always adding sequence, regardless of if we're the only handler or if there are others. So I think the complexity shouldn't be much higher than for handleError

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think if we keep the function declaration (with function _handleError) we should be fine - if this takes too much time though (more the 2 hours), it's probably not worth it.

Copy link
Copy Markdown
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Turns out, it wasn't all too hard to get this working (albeit not pretty either). So I just did it in this PR 0a50651

Copy link
Copy Markdown
Contributor

@AbhiPrasad AbhiPrasad left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Let's merge this in - you can add the changes to wrapping function exports in another PR if you decide its worth the time - sorry for not LOGAFing.

@Lms24 Lms24 force-pushed the lms/sveltekit-support branch from 753065f to f37bfe4 Compare April 21, 2023 10:32
@Lms24 Lms24 force-pushed the lms/just-ast-things-ii branch from 6cbeba7 to 4194da9 Compare April 21, 2023 10:33
@Lms24
Copy link
Copy Markdown
Member Author

Lms24 commented Apr 21, 2023

Let's merge this in - you can add the changes to wrapping function exports in another PR if you decide its worth the time - sorry for not LOGAFing.

All good! It's a valid concern! I'll take another look at it

@Lms24 Lms24 merged commit a278a4a into lms/sveltekit-support Apr 21, 2023
@Lms24 Lms24 deleted the lms/just-ast-things-ii branch April 21, 2023 11:18
Lms24 added a commit that referenced this pull request May 3, 2023
…oks (#259)

Add our handlers to the `handle` and `handleError` hooks in the SveltKit hooks files. Uses magicast and advanced AST manipulation to merge user-defined handlers with ours.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants