mirror of
https://we.phorge.it/source/arcanist.git
synced 2024-11-22 14:52:40 +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:
parent
802c0ed89f
commit
f649837785
3 changed files with 37 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -1287,4 +1287,10 @@ abstract class ArcanistBaseWorkflow {
|
|||
return $editor;
|
||||
}
|
||||
|
||||
protected function newDiffParser() {
|
||||
$parser = new ArcanistDiffParser();
|
||||
$parser->setWriteDiffOnFailure(true);
|
||||
return $parser;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -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);
|
||||
|
||||
|
|
Loading…
Reference in a new issue