This is an archive of the discontinued LLVM Phabricator instance.

[clangd][tests] Add exit(EXIT_FAILURE) in case of JSON parsing failure in TestMode
Needs ReviewPublic

Authored by jkorous on Aug 15 2018, 9:16 AM.

Details

Summary

This is meant to cause a visible fail when clangd gets invalid JSON payload in -lit-test mode.

Based on discussion in https://reviews.llvm.org/D50641 (and http://lists.llvm.org/pipermail/clangd-dev/2018-August/000072.html).

Diff Detail

Event Timeline

jkorous created this revision.Aug 15 2018, 9:16 AM

I think propagating the 'test' yes/no value is not the best way to describe the intention of this change.
Our intention is to exit from the LSP server on JSON error. One way to describe this intention better is to propagate a boolean 'exitOnJSONError' value.
Furthermore, If you think about the '-llvm-lit' flag itself you'll see that it acts an abbreviation for these 3 options: -input-style=delimited -pretty -run-synchronously. I think that it would be valuable to follow this intention and to add a new option (e.g. -exit-on-json-error) that will then be set when -llvm-lit is set.
WDYT?

+1 to having a separate option for that. More generally, wouldn't we want to exit on more kinds errors in the future?
JSON parsing errors is something that popped up recently, but the option only for that looks too narrow. We might end up wanting more options like that in the future, e.g. -exit-on-json-dispatch-error, -exit-on-parse-error, ...

How about a more generic option that would force clangd to have non-zero error code whenever even a single error was emitted via elog()?
I've checked the output of ./bin/llvm-lit -avv ../tools/clang/tools/extra/test/clangd/ | grep '\(^E\|PASS\)' and there seems to be a few things that emit errors spuriously and should be fixed for that to work:

  1. E[10:19:11.985] Failed to get status for RootPath clangd: No such file or directory.

Could be fixed by specifying a valid rootPath in all clangd tests.

  1. E[10:19:12.013] Could not build a preamble for file /clangd-test/main.cpp.

IIUC, this happens on empty preambles, the fix is to not emit an error in that case. In general, whenever preamble is not built, this is probably due to changes in some headers and that case should be considered valid input for clangd, so arguably this shouldn't be an error in the first place.-

  1. Some tests actually test for invalid inputs, those should probably expect an error code from clangd that runs into those errors.

That doesn't look like a long list, so it shouldn't be too hard. What are your thoughts on a more generic option like that?

JSONRPCDispatcher.cpp
366

Alternative would be to run input parsing to completion, propagate if any error was encountered to main and exit with a predefined error code in that case.
Exiting prematurely might hide some important errors that we would otherwise catch even before seeing an error code from clangd, e.g. infinite loops in the input handling on invalid inputs, etc.

Oh, I thought that what everyone wanted was test-specific behaviour. I like both approaches you propose much more!
If we go for the generic option we can effectively start "checking stderr" in tests by using the flag. That would be nice.

Just to be sure we are all on the same page:

  1. Do we want to exit right after elog() call?
  2. Do we consider calling exit() in elog() smart or hacky?

Based on quick grepping if we'd like to propagate errors probably the biggest challenge would be ASTWorker.