path-to-regexp icon indicating copy to clipboard operation
path-to-regexp copied to clipboard

Improve error message when parsing fails

Open simhnna opened this issue 1 year ago • 4 comments

I got error messages like TypeError: Missing parameter name at 3: https://git.new/pathToRegexpError and I was wondering how that weird url made it's way into my code

Two suggestions:

  1. It doeesn't look like lexer() gets the whole error, so maybe it would be good to wrap those errors in parse() and include the whole string?
  2. Make it clear that the url is documentation. Something like For more information about regexp paths check https://...
  3. I personally would prefer a link that clearly shows it's going to github instead of a link shortener, but that's just my opinion

If you're ok with me changing 1 and 2, I'm happy to prepare a pull request

simhnna avatar Oct 17 '24 10:10 simhnna

  1. I'm not sure I understand, can you elaborate on what "the whole string"?
  2. Sounds good, I'm open to a PR that changes it to something like ...; visit <link> for more information.
  3. Prefer to avoid changing for now, it's there to ensure the error docs can move or update in the future without breaking old versions of the library.

blakeembrey avatar Oct 17 '24 18:10 blakeembrey

For 1, I guess the problem is that the error message gives no indication on where the error occurred. I have the same error stating something about 'missing parameter name at 2' without any details. So I have to check all my routes for potential errors. Dumping the input path will already help with handling this error.

abs-lme avatar Apr 01 '25 16:04 abs-lme

I'm sorry I completely forgot about that. I created two merge requests that address points 1 and 2

simhnna avatar Apr 07 '25 08:04 simhnna

I have created a simple version of this that shows you the problematic url. pull request #358

SlothScript avatar Apr 15 '25 23:04 SlothScript