Comments (10)
I've been giving this some more thought and I'm leaning towards keeping TypeError and not using SyntaxError. Here are my reasons.
- Using SyntaxError would result in some weird inconsistencies since URLPattern builds on URL in places. Consider that
new URL("blarg")
would throw a TypeError, butnew URLPattern({ baseURL: "blarg" })
would throw a SyntaxError. This seems weird to me. - URLPattern is closer to URL than it is to RegExp. The URLPattern constructor and its getters are fairly closely duck typed to URL. URLPattern does provide
test()
andexec()
methods similar to RegExp, but those do not throw SyntaxErrors as far as I know. - I've received spec guidance in the past (I think from @annevk) that in general its not worth over specifying the type of exceptions and APIs should just throw TypeError. I believe this guidance is based on the experience with trying to create granular DOM exceptions in the past.
- Its asserted above that URL using TypeError instead of SyntaxError is a mistake, but I don't see any issues having ever been opened on the URL spec about that. If it is a problem it doesn't seem very significant.
from urlpattern.
Hmm, fair point. I guess in an ideal world new URL()
would also be using SyntaxError
. But given that it isn't, we have to decide whether URL pattern strings are more like RegExps (SyntaxError) or more like URLs (TypeError).
My instinct is they're more like URLs, but it might be reasonable to leave this open to get a bit more feedback. (And close it if nobody has any after a week or so.)
from urlpattern.
These feel like they're pretty much halfway between URLs and RegExps to me, so either precedent would be reasonable, which means looking at precedent doesn't help much. From first principles, SyntaxError seems like it makes more sense than TypeError to me as a user, when I write a pattern that has incorrect syntax - "SyntaxError" sounds like "you wrote the string wrong", "TypeError" sounds like "I was expecting you to pass an object rather than a string".
(I don't think it'll matter in practice much either way, though, as long as browsers do a decent job explaining what the problem is in the .message
.)
from urlpattern.
I'm going to go ahead and call this decided for now.
from urlpattern.
That's not correct; SyntaxError is used for regexp string syntax errors, as well as BigInt string parsing syntax errors and JSON string parsing syntax errors. It's not constrained to JS source code but instead is used for a variety of parsers in the JS spec.
from urlpattern.
So per Allen using it for JSON was a mistake, the others all seem like JS source code, but I guess some of that is debatable. Web IDL also still recommends against using it within the web platform.
from urlpattern.
I'm personally in favor of using TypeError as it matches new URL()
behavior when its passed a bad URL. @domenic, is that compelling to you?
from urlpattern.
Given that URL "should" be SyntaxError, why perpetuate the "mistake"?
from urlpattern.
Not sure it matters much to the outcome here, but path-to-regexp currently throws TypeError. Just another data point.
from urlpattern.
I'm pretty sure that SyntaxError
is meant exclusively for JavaScript source text syntax errors and is not to be used for other types of syntax errors. See https://www.w3.org/Bugs/Public/show_bug.cgi?id=26961.
Or do you mean "SyntaxError
" DOMException
? The reason I'm not using that is to make APIs less browser-centric.
from urlpattern.
Related Issues (20)
- Base URL inheritance gives unintuitive results HOT 21
- Consider creating a RFC for base functionality HOT 2
- Add a "using URLPattern in other APIs" section HOT 9
- Backslash escaping is required for colon before password in string syntax
- WHATWG migration HOT 5
- Attribute to show the regular expression usage. HOT 9
- Hash test matching different from path matching HOT 1
- Consider cleaning up extra markdown documents
- Custom named full-wildcard HOT 2
- Base URL and empty pathname in URLPatternInit
- Incorrect handling of base URL in URLPatternInit processing HOT 10
- Loose base URL check can crash URL parser HOT 5
- Handling of special character in hostname
- More consistent and robust segment wilcard generation
- Incorrect type in group name assignment
- "Hostname pattern is an IPv6 address" called with `null` HOT 1
- Constructor string parser has confusing result for paths containing a colon. HOT 1
- The way to integrate the API without depending on ECMAScript realm. HOT 3
- Accept URL as the match algorithm's input. HOT 4
- Opaque Host and domain encoding HOT 6
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from urlpattern.