-
-
Notifications
You must be signed in to change notification settings - Fork 394
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
check whether prevOpts is nil in WipeoutBuildPathIfBuildOptionsChanged's Run #1118
Conversation
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.
Hm, do you know when this situation occurs exactly? It looks like a non-existing build options JSON file is handled already:
if ctx.BuildOptionsJsonPrevious == "" { | |
return nil | |
} |
So apparently the JSON contents is non-empty, but is invalid JSON or something, resulting in a nil
prevOpts
? Any idea what's in there?
In any case: handling invalid build options JSON by doing a cleanup seems like a good approach.
I would suggest printing a message when this happens, to help debugging weird situations like these, but it seems that currently no log messages are being printed from this context:
// FIXME: this should go outside legacy and behind a `logrus` call so users can | |
// control when this should be printed. | |
// logger.Println(constants.LOG_LEVEL_INFO, constants.MSG_BUILD_OPTIONS_CHANGED) |
Maybe add a TODO comment about logging a message?
I can add a message in this PR when this occurs. |
esp8266/Arduino CI's builder script didn't recently receive significant change. We are able to reproduce the issue locally by replaying esp8266/Arduino github CI steps and one need to find which commit of arduino-builder or arduino-cli introduced the issue. To answer your question, here's the loop over tested sketches that is run by our CI. Maybe that this piece of script needs to be updated, and I think it should happen after arduino-builder is segfault-proof. |
Cool! I like the structure of the code better as well like this (harder to accidentally introduce a nil-pointer reference again later). I'm not entirely sure about the message itself, "unusual state to investigate" is a bit vague and broad, maybe use something like:
But maybe @cmaglie or one of the other maintainers have a more relevant opinion on that :-)
Yeah, this should certainly be fixed in arduino-cli, regardless of changes on your side, I agree. Looking at your script, it does indeed mess around with To fix this on your end, I would suggest looking at the |
Thanks alot. We'll certainly have a try with updating our script (cc @earlephilhower FYI).
Thanks for the suggestion. I just pushed an update with your proposal. |
Thanks d-a-v. This looks like a nice improvement to Arduino CLI! The current approach:
assumes that a corrupted build.options.json will always result in prevOpts being nil , but it sounds like json.Unmarshal() is designed to populate v with as much of the data as it is able to unmarshal, and indicate there were problems by returning an error:https://golang.org/pkg/encoding/json/#Unmarshal
I wonder if it would be better practices to do something like this instead: index 57be5983..d5052d54 100644
--- a/legacy/builder/wipeout_build_path_if_build_options_changed.go
+++ b/legacy/builder/wipeout_build_path_if_build_options_changed.go
@@ -42,7 +42,10 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error {
var opts *properties.Map
var prevOpts *properties.Map
json.Unmarshal([]byte(buildOptionsJson), &opts)
- json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts)
+ if err := json.Unmarshal([]byte(previousBuildOptionsJson), &prevOpts); err != nil {
+ ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_BUILD_OPTIONS_INVALID, constants.BUILD_OPTIONS_FILE)
+ return doCleanup(ctx.BuildPath)
+ }
// If SketchLocation path is different but filename is the same, consider it equal
if filepath.Base(opts.Get("sketchLocation")) == filepath.Base(prevOpts.Get("sketchLocation")) { Of course, it's unlikely that the non-nil null |
@per1234 good catch, your proposal sounds good to me. The |
thank you @matthijskooijman and @per1234 for chiming in. let's see how this develops :) |
@@ -40,9 +42,16 @@ func (s *WipeoutBuildPathIfBuildOptionsChanged) Run(ctx *types.Context) error { | |||
previousBuildOptionsJson := ctx.BuildOptionsJsonPrevious | |||
|
|||
var opts *properties.Map | |||
if err := json.Unmarshal([]byte(buildOptionsJson), &opts); err != nil || opts == nil { | |||
ctx.GetLogger().Println(constants.LOG_LEVEL_DEBUG, constants.MSG_BUILD_OPTIONS_INVALID, constants.BUILD_OPTIONS_FILE) |
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.
I think this message is confusing:
build.options.json invalid
Because it's not the build.options.json file that's invalid, but rather the internal build options data.
Since this isn't something that should occur under any normal circumstances, I would lean toward just doing a panic(err)
. Probably @silvanocerza would be able to tell us what is the preferred approach though.
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.
I think it's fine like this, it seems to me that ctx.BuildOptionsJson
is populated with data from the build.options.json
file only.
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.
The build.options.json
file is created from ctx.BuildOptionsJson
:
ctx.BuildPath.Join(constants.BUILD_OPTIONS_FILE).WriteFile([]byte(ctx.BuildOptionsJson)) |
It's
ctx.BuildOptionsJsonPrevious
that is populated with data from the build.options.json
file:ctx.BuildOptionsJsonPrevious = string(bytes) |
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.
Should I leave it as it currently is,
or change the message,
or replace it by panic(constants.BUILD_OPTIONS_FILE + " is invalid")
?
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.
I'd like to get @silvanocerza's response to my previous reply just to make sure everyone is on the same page here. After that, I'd recommend going with whatever Silvano think is best.
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.
Sorry, forgot about this.
@per1234 is right, probably a message like build options are invalid
might be less confusing, it's not exactly transparent like this either but at least it won't confuse the user if the build.options.json
file doesn't exist.
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.
@silvanocerza @per1234 I just proceeded with your suggestion.
@d-a-v could you write an integration test or a list of steps to reproduce the issue this PR fixes? |
@silvanocerza I made a PR in esp8266/Arduino that will reproduce the original issue. edit in this link, Arduino-IDE-nightly is used. Does it use arduino-cli nightly ? |
@silvanocerza here are minimal instructions to reproduce the issue:
Without the changes made in this PR, both the above The above only exercises the changes made to the unmarshalling of |
Co-authored-by: per1234 <accounts@perglass.com>
dc872c1
to
4d5a247
Compare
@d-a-v I pushed the tests and rebased the branch to solve some issues, you'll have conflicts for sure if you fetch the branch. If all tests pass I'll merge it, if there are no issue you'll probably see it really soon in the |
Thanks ! |
Merged, thanks @d-a-v for the contribution! |
…1118) * check whether prevOpts is nil in WipeoutBuildPathIfBuildOptionsChanged's Run * + debug message * update from review: improve user message * fix per review * add check to buildOptionsJson too * panic'ing instead of keeping on with mess * fix use of a constant Co-authored-by: per1234 <accounts@perglass.com> * [skip changelog] Add compile with invalid build.options.json test Co-authored-by: per1234 <accounts@perglass.com> Co-authored-by: Silvano Cerza <silvanocerza@gmail.com>
Please check if the PR fulfills these requirements
before creating one)
our contributing guidelines
UPGRADING.md
has been updated with a migration guide (for breaking changes)arduino-1.8.10 is able to run esp8266/Arduino CI tests, but not anymore since 1.8.11..1.8.13 (example).
This PR fixes it.
I haven't tried to understand what happened between arduino-ide 1.8.10 and 1.8.11.