-
Notifications
You must be signed in to change notification settings - Fork 17
Make error handling optionally more permissive. #58
Conversation
Fixes a bug.
lib/src/package_config_json.dart
Outdated
onError(PackageConfigFormatException(e.message, e.source, e.offset)); | ||
return null; | ||
} on Object catch (e) { | ||
print("WTF: $e"); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe not...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Debug-print, FTW!
For the following packages file:
I get 3 errors:
Also - even though it's a FormatException with support for a location, there is none... |
lib/src/package_config_impl.dart
Outdated
checkValidVersionNumber(languageVersion) >= 0) { | ||
onError(PackageConfigArgumentError(languageVersion, "languageVersion", | ||
"Invalid language version format")); | ||
languageVersion = null; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Could we get a special marker for invalid language version?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
What kind of "special marker"?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So a client can tell that a language version was set, although it was invalid. It my suggested hack-patch I simply overwrite the string "invalid" instead of null --- though something more elegant is surely possible...
just gets language version 2.5. |
While this might not be pretty, this fixes the most severe issues I have:
It does not add offsets, but that's only a minor issue I think. |
That's a lot of errors. I'll try fixing the issue instead. |
Make more errors be format exceptions with offset. Don't continue with an invalid value. Instead either sanitize the value, if possible, ignore it if it was optional, or bail out if it is required.
Allow invalid language versions to be detectable.
- Do not require root URIs to have paths starting with `/`. That | ||
only makes sense for `file` or `http`, and they enforce it anyway. | ||
- Fixed bug in language version validation not accepting the digit `9`. | ||
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Missing entry for language version becoming an object rather than a string.
throw PackageConfigFormatException(e.message, e.invalidValue); | ||
|
||
LanguageVersion /*?*/ version; | ||
if (languageVersion != null) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
languageVersion is null if it's not a string in the json format (line 240 --- for some reason I cannot mark that line).
pubspec.yaml
Outdated
@@ -1,15 +1,11 @@ | |||
name: package_config | |||
version: 2.0.0 | |||
name: package_config_2 |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This would require tests to be updated too, right?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It should match, I forgot to change this one back after running tests.
Don't write invalid language versions.
fb180d4
to
d7f133c
Compare
d7f133c
to
cbd07f9
Compare
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM.
…nfig#58) * Make error handling optionally more permissive. * Make the LanguageVersion be an object, not a string. * Make it version 3.0.0-dev
Fixes a bug.