1
0
Fork 0
mirror of https://we.phorge.it/source/arcanist.git synced 2024-11-22 23:02:41 +01:00

Dump problematic parser patches to temp files in "arc diff"

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
This commit is contained in:
epriestley 2012-07-17 16:16:18 -07:00
parent 802c0ed89f
commit f649837785
3 changed files with 37 additions and 8 deletions

View file

@ -30,6 +30,8 @@ final class ArcanistDiffParser {
protected $isMercurial; protected $isMercurial;
protected $detectBinaryFiles = false; protected $detectBinaryFiles = false;
protected $tryEncoding; protected $tryEncoding;
protected $rawDiff;
protected $writeDiffOnFailure;
protected $changes = array(); protected $changes = array();
private $forcePath; private $forcePath;
@ -957,6 +959,7 @@ final class ArcanistDiffParser {
} }
protected function didStartParse($text) { protected function didStartParse($text) {
$this->rawDiff = $text;
// Eat leading whitespace. This may happen if the first change in the diff // Eat leading whitespace. This may happen if the first change in the diff
// is an SVN property change. // is an SVN property change.
@ -1026,9 +1029,15 @@ final class ArcanistDiffParser {
$this->text = null; $this->text = null;
} }
public function setWriteDiffOnFailure($write) {
$this->writeDiffOnFailure = $write;
return $this;
}
protected function didFailParse($message) { protected function didFailParse($message) {
$min = max(0, $this->line - 3); $context = 3;
$max = min($this->line + 3, count($this->text) - 1); $min = max(0, $this->line - $context);
$max = min($this->line + $context, count($this->text) - 1);
$context = ''; $context = '';
for ($ii = $min; $ii <= $max; $ii++) { for ($ii = $min; $ii <= $max; $ii++) {
@ -1039,8 +1048,21 @@ final class ArcanistDiffParser {
$this->text[$ii]); $this->text[$ii]);
} }
$message = "Parse Exception: {$message}\n\n{$context}\n"; $out = array();
throw new Exception($message); $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);
} }
/** /**

View file

@ -1287,4 +1287,10 @@ abstract class ArcanistBaseWorkflow {
return $editor; return $editor;
} }
protected function newDiffParser() {
$parser = new ArcanistDiffParser();
$parser->setWriteDiffOnFailure(true);
return $parser;
}
} }

View file

@ -667,7 +667,7 @@ EOTEXT
protected function generateChanges() { protected function generateChanges() {
$parser = new ArcanistDiffParser(); $parser = $this->newDiffParser();
$is_raw = $this->isRawDiffSource(); $is_raw = $this->isRawDiffSource();
if ($is_raw) { if ($is_raw) {
@ -908,7 +908,8 @@ EOTEXT
// textual data. // textual data.
if ($change->getNeedsSyntheticGitHunks()) { if ($change->getNeedsSyntheticGitHunks()) {
$diff = $repository_api->getRawDiffText($path, $moves = false); $diff = $repository_api->getRawDiffText($path, $moves = false);
$parser = new ArcanistDiffParser(); $parser = $this->newDiffParser();
$raw_changes = $parser->parseDiff($diff); $raw_changes = $parser->parseDiff($diff);
foreach ($raw_changes as $raw_change) { foreach ($raw_changes as $raw_change) {
if ($raw_change->getCurrentPath() == $path) { if ($raw_change->getCurrentPath() == $path) {
@ -1008,7 +1009,7 @@ EOTEXT
$conduit = $this->getConduit(); $conduit = $this->getConduit();
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
$parser = new ArcanistDiffParser(); $parser = $this->newDiffParser();
$history_messages = $repository_api->getGitHistoryLog(); $history_messages = $repository_api->getGitHistoryLog();
if (!$history_messages) { if (!$history_messages) {
// This can occur on the initial commit. // This can occur on the initial commit.
@ -1842,7 +1843,7 @@ EOTEXT
private function getGitUpdateMessage() { private function getGitUpdateMessage() {
$repository_api = $this->getRepositoryAPI(); $repository_api = $this->getRepositoryAPI();
$parser = new ArcanistDiffParser(); $parser = $this->newDiffParser();
$commit_messages = $repository_api->getGitCommitLog(); $commit_messages = $repository_api->getGitCommitLog();
$commit_messages = $parser->parseDiff($commit_messages); $commit_messages = $parser->parseDiff($commit_messages);