denoland / deno

A modern runtime for JavaScript and TypeScript.
https://deno.com
MIT License
96.95k stars 5.35k forks source link

Poor dynamic route syntax results in less-than-perfect error message #25965

Open johnstonmatt opened 4 weeks ago

johnstonmatt commented 4 weeks ago

I've found that if you create a dynamic route in the form of [:myparam].tsx rather than [myparam].tsx the error message is

error: Uncaught (in promise) TypeError: tokenizer error: invalid name; must be at least length 1 (at char 1)
        path: new URLPattern({ pathname }),
              ^
    at new URLPattern (ext:deno_url/01_urlpattern.js:190:24)
    at UrlPatternRouter.add (https://jsr.io/@fresh/core/2.0.0-alpha.20/src/router.ts:55:15)
    at App.#addRoutes (https://jsr.io/@fresh/core/2.0.0-alpha.20/src/app.ts:166:18)
    at App.get (https://jsr.io/@fresh/core/2.0.0-alpha.20/src/app.ts:106:27)
    at fsRoutes (https://jsr.io/@fresh/core/2.0.0-alpha.20/src/plugins/fs_routes/mod.ts:316:21)

If this is sufficient and you aren't interested in more friendly debugging output feel free to close, it isn't all that hard to figure out, but I just hit it twice in a row and figured I'd call it out.

https://github.com/denoland/fresh/blob/b5389f69a384280319d815d6f35dd9743f0738b2/src/router.ts#L55

marvinhagemeister commented 3 weeks ago

Transferring to the main Deno repo, because it's about error messages from URLPattern

lucacasonato commented 3 weeks ago

Minimum reproduction for the error message: new URLPattern({ pathname: "/::name" })