-
Notifications
You must be signed in to change notification settings - Fork 20
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Validate target type for all option fields, not just features #279
Conversation
d41ca4c
to
60f81f4
Compare
…ential nil dereference panic that isn't covered by tests, so fixed all references to interp.resolver that weren't doing nil check
60f81f4
to
5ecc9ad
Compare
@emcfarlane, this is the reason I did the pre-factoring in #281, so we have coverage of the way the code can now keep going and return both a nil/invalid result and a nil error. There are changes to the message literal processing that involved un-indenting a block of code (to improve the control flow with an |
…ld#279) The code to verify that a feature field was only used on particular kind of element was features-specific. However, in `protoc`, it is not features-specific and applies to _all_ option fields that have a `targets` option defined. So this updates protocompile to behave the same way. This PR is a bit complicated because I had to change the error handling of the `*interpreter.fieldValue` method (and the `setOptionField` method that called it, as well as numerous methods that it used). It previously either returned a value or an error. If it returned an error, it would be reported by the caller. But now, these places handle the errors, to allow reporting of multiple errors for the same option value. This change in behavior is the reason for most of the churn/change in the code. The change to just the target type validation is actually a net simplification. (cherry picked from commit e8799f7)
…ld#279) The code to verify that a feature field was only used on particular kind of element was features-specific. However, in `protoc`, it is not features-specific and applies to _all_ option fields that have a `targets` option defined. So this updates protocompile to behave the same way. This PR is a bit complicated because I had to change the error handling of the `*interpreter.fieldValue` method (and the `setOptionField` method that called it, as well as numerous methods that it used). It previously either returned a value or an error. If it returned an error, it would be reported by the caller. But now, these places handle the errors, to allow reporting of multiple errors for the same option value. This change in behavior is the reason for most of the churn/change in the code. The change to just the target type validation is actually a net simplification. (cherry picked from commit e8799f7)
) The panic fix is tiny. But this commit is bigger because other changes/improvements were called for: most of the code changes are to improve error handling when in lenient mode. After I fixed the panic, the test case was failing in a different way, due to an issue with how errors (even in lenient mode) were still being passed to an error reporter and causing the stage to fail. This issue was introduced in #279. That PR moved things around, pushing the responsibility of calling `interp.reporter.HandleError` down, so that interpreting a single option could potentially report multiple errors (instead of failing fast and only reporting the first). But when in lenient mode, we don't actually want to send those errors to the reporter: sending the error to the reporter meant the error would get memoized and then returned in subsequent handle calls, which could cause the process to fail when it should be lenient and also can cause it to report the wrong error in lenient mode. So now we demarcate the parts of the process where errors are tolerated (i.e. where lenience mode is actually activated) with a new field on the interpreter that is examined when errors are reported.
The code to verify that a feature field was only used on particular kind of element was features-specific. However, in
protoc
, it is not features-specific and applies to all option fields that have atargets
option defined.This PR is a bit complicated because I had to change the error handling of the
*interpreter.fieldValue
method (and thesetOptionField
method that called it, as well as numerous methods that it used). It previously either returned a value or an error. If it returned an error, it would be reported by the caller. Even in the previous iteration of the code, this was not optimal because it meant that we had to abort processing an option value after the first error, instead of being able to potentially report multiple errors in the same option. But now, since thetargets
usage really doesn't impact the rest of the processing of an option value, it seems weird to abort that processing just because of a target type usage issue.So now, the
*interpreter.fieldValue
method handles the errors that come up and only returns a non-nil error if the handler returns a non-nil error. That means calling code can no longer rely onerr == nil
but must separately check that the other returned value is valid/non-nil.This change is the cause for most of the change/churn in the code.
The actual change to target type validation is a net simplification, which is nice.