roaster icon indicating copy to clipboard operation
roaster copied to clipboard

specify ambiguous routes

Open nverwer opened this issue 2 years ago • 7 comments

When a path is ambiguous, log the matching routes.

nverwer avatar Jun 19 '23 15:06 nverwer

Test are failing. I will check locally what is going wrong.

line-o avatar Jul 12 '23 10:07 line-o

With eXist-7.0.0-SNAPSHOT we have 11 failing tests (custom authorisation and file upload are affected it seems).

line-o avatar Jul 12 '23 15:07 line-o

@nverwer I do like the idea of displaying more debug information when a developer wants to learn which routes are ambigous. The way the log message is constructed was and is suboptimal because string operations like concatenation will always be performed before the log message is later discarded. I would rather like to see route definitions to be passed in as additional data

     util:log("debug", ("ambiguous route: ", $request-data?path, " matching routes: ", $matching-routes)),

line-o avatar Jul 12 '23 15:07 line-o

I revisited and tested my proposal and came up with

util:log("debug", map {
  "ambiguous route" : $request-data?path,
  "matching definitions" : array { $matching-routes?path }
})

Which would give us

[...] DEBUG  [...] map{"ambiguous route":"/api/errors/handle","matching definitions":["/api/errors/handle","/api/errors/handle"]}

@nverwer would that be enough information to determine which route definitions are ambigous or do you need more?

line-o avatar Jul 13 '23 15:07 line-o

I just see that the path is not good enough as both are steh same when in fact it is to different ones. And the specificity and priority might be of interest as well.

line-o avatar Jul 13 '23 20:07 line-o

Hello @line-o , Since the information about ambiguities is primarily interesting for developers, I would indeed want to see the specificity and priority of the matching routes. So how about something like

util:log("debug", map {
  "ambiguous route" : $request-data?path,
  "matching definitions" : array { $matching-routes }
})

without the path?

I did not actually try this (yet).

nverwer avatar Jul 15 '23 13:07 nverwer

@nverwer and I put our heads together and came up with this solution:

map{
    "ambiguous route":"/api/errors/handle",
    "method": "get",
    "matching definitions":[
        map{
            "priority": 1,
            "specificity": 11,
            "pattern": "/api/errors"
        },
        map{
            "priority": 1,
            "specificity": 18,
            "pattern": "/api/errors/handle"
        }
    ]
}

will be logged for the one (test-)request that matches two routes.

line-o avatar Jul 15 '23 15:07 line-o

:tada: This PR is included in version 1.9.0 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

github-actions[bot] avatar Aug 26 '24 16:08 github-actions[bot]