Commit 86e95b3c authored by cjhopman's avatar cjhopman Committed by Commit bot

GN: Store parse error messages (so they aren't dropped due to races)

Bad error messages remind me of working with gyp.

This change just stores the parser error in the InputFileData so that we
can actually report a useful error message from whichever thread first
reports an error.

Review URL: https://codereview.chromium.org/645253002

Cr-Commit-Position: refs/heads/master@{#299953}
parent 2772be93
......@@ -215,20 +215,12 @@ const ParseNode* InputFileManager::SyncLoadFile(
}
}
// The other load could have failed. In this case that error was probably
// printed to the console, but we need to return something here, so make up a
// dummy error.
//
// There is a race condition. The other load could have failed, but if the
// other thread is delayed for some reason, this thread could end up
// reporting the error to the scheduler first (since first error report
// wins). The user will see this one and the "real" one will be discarded.
if (!data->parsed_root) {
*err = Err(origin, "File parse failed.",
"If you see this, I'm really sorry, but a race condition has caused\n"
"me to eat your error message. It was crunchy. If the parse error\n"
"in your imported file isn't obvious, try re-running GN.");
}
// The other load could have failed. It is possible that this thread's error
// will be reported to the scheduler before the other thread's (and the first
// error reported "wins"). Forward the parse error from the other load for
// this thread so that the error message is useful.
if (!data->parsed_root)
*err = data->parse_error;
return data->parsed_root.get();
}
......@@ -296,6 +288,8 @@ bool InputFileManager::LoadFile(const LocationRange& origin,
if (success) {
data->tokens.swap(tokens);
data->parsed_root = root.Pass();
} else {
data->parse_error = *err;
}
// Unblock waiters on this event.
......
......@@ -117,6 +117,7 @@ class InputFileManager : public base::RefCountedThreadSafe<InputFileManager> {
// Null before the file is loaded or if loading failed.
scoped_ptr<ParseNode> parsed_root;
Err parse_error;
};
virtual ~InputFileManager();
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment