From 010892bf87d91e973c6bc54addd38713d9a18822 Mon Sep 17 00:00:00 2001 From: Aiden Scandella Date: Tue, 9 Jun 2015 09:19:25 -0700 Subject: [PATCH] Handle invalid responses from arc call-conduit To help debug errors like #30 --- .../phabricator/PhabricatorBuildWrapper.java | 1 + .../phabricator/conduit/Differential.java | 23 ++++++++++++++++++- 2 files changed, 23 insertions(+), 1 deletion(-) diff --git a/src/main/java/com/uber/jenkins/phabricator/PhabricatorBuildWrapper.java b/src/main/java/com/uber/jenkins/phabricator/PhabricatorBuildWrapper.java index 484915f9..3858a152 100644 --- a/src/main/java/com/uber/jenkins/phabricator/PhabricatorBuildWrapper.java +++ b/src/main/java/com/uber/jenkins/phabricator/PhabricatorBuildWrapper.java @@ -97,6 +97,7 @@ public Environment setUp(AbstractBuild build, diff.postComment(diff.getBuildStartedMessage(environment)); } catch (ArcanistUsageException e) { logger.println("[arcanist] unable to apply patch"); + logger.println(e.getMessage()); return null; } diff --git a/src/main/java/com/uber/jenkins/phabricator/conduit/Differential.java b/src/main/java/com/uber/jenkins/phabricator/conduit/Differential.java index 29c1ca60..00873923 100644 --- a/src/main/java/com/uber/jenkins/phabricator/conduit/Differential.java +++ b/src/main/java/com/uber/jenkins/phabricator/conduit/Differential.java @@ -26,6 +26,7 @@ import hudson.EnvVars; import hudson.model.AbstractBuild; import hudson.model.Result; +import net.sf.json.JSONException; import net.sf.json.JSONNull; import net.sf.json.JSONObject; @@ -49,7 +50,27 @@ public Differential(String diffID, LauncherFactory launcher, String conduitToken params.put("ids", new String[]{diffID}); JSONObject query = this.callConduit("differential.querydiffs", params); - this.rawJSON = (JSONObject) ((JSONObject) query.get("response")).get(diffID); + JSONObject response; + try { + response = query.getJSONObject("response"); + } catch (JSONException e) { + e.printStackTrace(); + throw new ArcanistUsageException( + String.format("No 'response' object found in conduit call: (%s) %s", + e.getMessage(), + query.toString(2))); + } + try { + this.rawJSON = response.getJSONObject(diffID); + } catch (JSONException e) { + e.printStackTrace(); + throw new ArcanistUsageException( + String.format("Unable to find '%s' key in response: (%s) %s", + diffID, + e.getMessage(), + response.toString(2))); + + } } public String getRevisionID(boolean formatted) {