Skip to content

Better error handling for invalid path #366

Closed
@phoenixstudiodz

Description

@phoenixstudiodz

Currently when a path is invalid the error is not very helpful, especially when code base is large.

I think this will be very helpful, in my case for example I am trying to migrate from express 4 to 5 (path-to-regexp v8.2.0)

Image

For now, I am using this to log errors

const pathToRegex = require("path-to-regexp");

const override = (functionName) => {
    const orgFunction = pathToRegex[functionName]
    pathToRegex[functionName] = function () {
        try{
            return orgFunction.call(this, ...arguments);
        }catch{
            console.error("error", functionName, arguments);
        }
        
    }
};

override("match")
override("pathToRegexp")
override("compile")
override("parse")
override("stringify")
// import and use express after the override

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions