Skip to content

TypeError: partialRoute.split is not a function #5481

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
3 tasks done
Michsior14 opened this issue Jul 28, 2022 · 7 comments · Fixed by #5483
Closed
3 tasks done

TypeError: partialRoute.split is not a function #5481

Michsior14 opened this issue Jul 28, 2022 · 7 comments · Fixed by #5483
Assignees
Labels
Package: node Issues related to the Sentry Node SDK

Comments

@Michsior14
Copy link

Michsior14 commented Jul 28, 2022

Is there an existing issue for this?

How do you use Sentry?

Sentry Saas (sentry.io)

Which package are you using?

@sentry/tracing

SDK Version

7.8.0

Framework Version

express 4.18.1, node 16.15.0

Link to Sentry event

No response

Steps to Reproduce

  1. Update @sentry/tracing to 7.8.0.
  2. Start the app
  3. Wait for incoming request

Expected Result

Requests to the server are processes properly without any errors.

Actual Result

Each request fails with the following error (probably related to #5450):

TypeError: partialRoute.split is not a function
    at Function.process_params (./main.js:2:1855298)
    at next (./main.js:2:2554914)
    at Function.handle (./main.js:2:2553813)
    at router (./main.js:2:2552432)
    at ./main.js:2:1853557
    at Layer.handle [as handle_request] (./main.js:2:2560503)
    at trim_prefix (./main.js:2:2555773)
    at ./main.js:2:2555055
    at Function.process_params (./main.js:2:2555954)
    at Function.process_params (./main.js:2:1856043)
@Lms24
Copy link
Member

Lms24 commented Jul 28, 2022

Hi @Michsior14 and thanks for reporting. That looks like a bug introduced in #5450. Apologies for that.
The error message you get makes me think that the partialRoute variable is not a string. It can't be undefined either (because we fall back to '' as a default directly above) so it must be something else.

In your reproduction steps, you said that starting the app is enough. Can you confirm that? Or does it crash at an incoming request? Thanks for your help!

@Lms24 Lms24 added Package: node Issues related to the Sentry Node SDK Status: In Progress and removed Status: Untriaged labels Jul 28, 2022
@Michsior14
Copy link
Author

@Lms24 Ups, sorry! I've updated the description, obviously it crashes on the request.

@Lms24
Copy link
Member

Lms24 commented Jul 28, 2022

Thanks for clarifying @Michsior14! I poked a bit at the express source code but couldn't yet find out how the layer.path or layer.route.path variables could be something other than undefined or string.

To help us debug this, could you tell us about your Express app? I'd be interested in your Sentry config as well as in a route that fails. Doesn't have to be the whole app but enough to reproduce this. Thanks!

@Michsior14
Copy link
Author

Michsior14 commented Jul 28, 2022

@Lms24 I found out what causes the issue. According to express docs it's allowed to define the paths as regex and one of my apps is using them a lot for different purposes. The code bellow with the latest SDK is a problem:

router.get(/\/file/, (_: express.Request, res: express.Response, next: express.NextFunction) => {
  next();
});

@Lms24
Copy link
Member

Lms24 commented Jul 28, 2022

Awesome, thanks @Michsior14! That makes sense. Now that we know how to reproduce it, we'll try to fix this asap.

Lms24 added a commit that referenced this issue Jul 28, 2022
make our URL parameterization for Express (introduced in #5450) compatible with RegEx-defined routes.

Previously, as reported in #5481, our parameterization logic would cause a crash because instead of a string, the matched route would be of type `RegExp`. This PR adjusts our logic so that we detect if we get a matched string our regex. In the latter case, we also append a `'/'` to the reconstructed partial route name so that the regex is closed.
@albanv
Copy link

albanv commented Jul 28, 2022

Hi @Lms24 just for you to know, arrays are also valids path parameters
we do encounter the exact same issue that the one described above when using an array as path.
Do you want me to open a separate issue or do you prefer re-open this one ?

@Lms24
Copy link
Member

Lms24 commented Jul 28, 2022

Ah I see, Express is really not making this easy 😅

If you have the time, please open a separate issue. We'll release the fix for this one today and I'll take a look at the arrays tomorrow. Thanks @albanv

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Package: node Issues related to the Sentry Node SDK
Projects
None yet
Development

Successfully merging a pull request may close this issue.

3 participants