]> khamidou — GitHub mirrors - arcanist.git/commitdiff
Dump problematic parser patches to temp files in "arc diff"
authorepriestley <git@epriestley.com>
Tue, 17 Jul 2012 23:16:18 +0000 (16:16 -0700)
committerepriestley <git@epriestley.com>
Tue, 17 Jul 2012 23:16:18 +0000 (16:16 -0700)
Summary: I'm trying to get a repro for a Windows + SVN patch issue. Dump patches which fail to a temp file so there's less bewilderment in getting the right patch handed over for analysis.

Test Plan: Forced a parse failure, ran "arc diff", inspected temp file.

Reviewers: btrahan, vrana

Reviewed By: btrahan

CC: aran
Differential Revision: https://secure.phabricator.com/D2997

src/parser/ArcanistDiffParser.php
src/workflow/ArcanistBaseWorkflow.php
src/workflow/ArcanistDiffWorkflow.php

index f95f12fe9e91a03873c8633459053413e86df49b..441a170b598e979f968e9647b723fccf3b7b0b85 100644 (file)
@@ -30,6 +30,8 @@ final class ArcanistDiffParser {
   protected $isMercurial;
   protected $detectBinaryFiles = false;
   protected $tryEncoding;
+  protected $rawDiff;
+  protected $writeDiffOnFailure;
 
   protected $changes = array();
   private $forcePath;
@@ -957,6 +959,7 @@ final class ArcanistDiffParser {
   }
 
   protected function didStartParse($text) {
+    $this->rawDiff = $text;
 
     // Eat leading whitespace. This may happen if the first change in the diff
     // is an SVN property change.
@@ -1026,9 +1029,15 @@ final class ArcanistDiffParser {
     $this->text = null;
   }
 
+  public function setWriteDiffOnFailure($write) {
+    $this->writeDiffOnFailure = $write;
+    return $this;
+  }
+
   protected function didFailParse($message) {
-    $min = max(0, $this->line - 3);
-    $max = min($this->line + 3, count($this->text) - 1);
+    $context = 3;
+    $min = max(0, $this->line - $context);
+    $max = min($this->line + $context, count($this->text) - 1);
 
     $context = '';
     for ($ii = $min; $ii <= $max; $ii++) {
@@ -1039,8 +1048,21 @@ final class ArcanistDiffParser {
         $this->text[$ii]);
     }
 
-    $message = "Parse Exception: {$message}\n\n{$context}\n";
-    throw new Exception($message);
+    $out = array();
+    $out[] = "Diff Parse Exception: {$message}";
+
+    if ($this->writeDiffOnFailure) {
+      $temp = new TempFile();
+      $temp->setPreserveFile(true);
+
+      Filesystem::writeFile($temp, $this->rawDiff);
+      $out[] = "Raw input file was written to: ".(string)$temp;
+    }
+
+    $out[] = $context;
+    $out = implode("\n\n", $out);
+
+    throw new Exception($out);
   }
 
   /**
index 4fe084f85b4a47fde4ba1255ef01d1f0f78b141e..301bd4c7aca1c9df3939e979c2445b887d684d46 100644 (file)
@@ -1287,4 +1287,10 @@ abstract class ArcanistBaseWorkflow {
     return $editor;
   }
 
+  protected function newDiffParser() {
+    $parser = new ArcanistDiffParser();
+    $parser->setWriteDiffOnFailure(true);
+    return $parser;
+  }
+
 }
index f45548f04cecff6cc120c74c5cdae7385e4d1b93..ac71aca369153caa51c880946dc486e078e3c76c 100644 (file)
@@ -667,7 +667,7 @@ EOTEXT
 
 
   protected function generateChanges() {
-    $parser = new ArcanistDiffParser();
+    $parser = $this->newDiffParser();
 
     $is_raw = $this->isRawDiffSource();
     if ($is_raw) {
@@ -908,7 +908,8 @@ EOTEXT
       // textual data.
       if ($change->getNeedsSyntheticGitHunks()) {
         $diff = $repository_api->getRawDiffText($path, $moves = false);
-        $parser = new ArcanistDiffParser();
+        $parser = $this->newDiffParser();
+
         $raw_changes = $parser->parseDiff($diff);
         foreach ($raw_changes as $raw_change) {
           if ($raw_change->getCurrentPath() == $path) {
@@ -1008,7 +1009,7 @@ EOTEXT
     $conduit = $this->getConduit();
     $repository_api = $this->getRepositoryAPI();
 
-    $parser = new ArcanistDiffParser();
+    $parser = $this->newDiffParser();
     $history_messages = $repository_api->getGitHistoryLog();
     if (!$history_messages) {
       // This can occur on the initial commit.
@@ -1842,7 +1843,7 @@ EOTEXT
   private function getGitUpdateMessage() {
     $repository_api = $this->getRepositoryAPI();
 
-    $parser = new ArcanistDiffParser();
+    $parser = $this->newDiffParser();
     $commit_messages = $repository_api->getGitCommitLog();
     $commit_messages = $parser->parseDiff($commit_messages);