Skip to content
This repository has been archived by the owner on Feb 2, 2021. It is now read-only.

json-stream reporter should always print at least {} on error #656

Open
bhamiltoncx opened this issue Jan 14, 2016 · 3 comments
Open

json-stream reporter should always print at least {} on error #656

bhamiltoncx opened this issue Jan 14, 2016 · 3 comments

Comments

@bhamiltoncx
Copy link
Contributor

I upgraded Xcode to 7.2 today without installing the simulators.

When I used xctool -reporter json-stream from Buck, Buck's JSON parser failed because xctool printed nothing to stdout (not even an empty JSON object {}). It did print an error message to stderr:

% /path/to/xctool -reporter json-stream -sdk iphonesimulator run-tests -logicTest /path/to/test.xctest
ERROR: SDK 'iphonesimulator' doesn't exist. Possible SDKs include:

It'd be nice if xctool could make sure to print a valid JSON object to stdout even on failure.

@bhamiltoncx
Copy link
Contributor Author

(This is arguably not really that big of a deal, so feel free to close if you don't agree. I just filed it in case you wanted to consider including error reporting inside json-stream or another reporter.)

@ExtremeMan
Copy link
Contributor

Thanks for filing. I will have a look if it is something easy to fix. We have many asserts in the code though. So if we even fix such error messages and log them appropriately to reporters we will hit the same issue if any of asserts fires.

@bhamiltoncx
Copy link
Contributor Author

Right. I think asserts are probably not the best check for a lot of these (especially ones which can fire due to user-provided data).

It's probably time to introduce real error-reporting infrastructure to xctool and stop relying on asserts :)

ghost pushed a commit to facebook/buck that referenced this issue Jan 15, 2016
Summary:
If xctool is in a bad state, it can close stdout before printing
anything (facebookarchive/xctool#656)

That makes the JSON parser in `XctoolOutputParsing` fail:

  com.google.gson.JsonIOException: java.io.EOFException: End of input at line 1 column 1
                                   at com.google.gson.JsonStreamParser.hasNext(JsonStreamParser.java:109)
                                   at com.facebook.buck.apple.XctoolOutputParsing.streamOutputFromReader(XctoolOutputParsing.java:147)
                                   at com.facebook.buck.apple.AppleTest$AppleTestXctoolStdoutReader.readStdout(AppleTest.java:138)
                                   at com.facebook.buck.apple.XctoolRunTestsStep.execute(XctoolRunTestsStep.java:292)
                                   at com.facebook.buck.step.DefaultStepRunner.runStepForBuildTarget(DefaultStepRunner.java:63)
                                   at com.facebook.buck.step.DefaultStepRunner$1.call(DefaultStepRunner.java:92)
                                   at java.util.concurrent.FutureTask.run(FutureTask.java:266)
                                   at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
                                   at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
                                   at java.lang.Thread.run(Thread.java:745)
  Caused by: java.io.EOFException: End of input at line 1 column 1
         at com.google.gson.stream.JsonReader.nextNonWhitespace(JsonReader.java:1377)
         at com.google.gson.stream.JsonReader.consumeNonExecutePrefix(JsonReader.java:1514)
         at com.google.gson.stream.JsonReader.doPeek(JsonReader.java:523)
         at com.google.gson.stream.JsonReader.peek(JsonReader.java:414)
         at com.google.gson.JsonStreamParser.hasNext(JsonStreamParser.java:105)
         ... 9 more

This fixes the issue by cleanly handling exceptions from `hasNext()` and just
ignoring the rest of the output.

Test Plan: Unit tests updated. Confirmed test failed before fix and passed after fix.

Reviewed By: ryu2

fb-gh-sync-id: 3d3a2e0
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Projects
None yet
Development

No branches or pull requests

2 participants