1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-11-26 16:52:41 +01:00

Add more type checking to transactions queued by Herald

Summary:
See PHI1096. Depends on D20213. An install is reporting a hard-to-reproduce issue where a non-transaction gets queued by Herald somehow. This might be in third-party code.

Sprinkle the relevant parts of the code with `final` and type checking to try to catch the problem before it causes a fatal we can't pull a stack trace out of.

Test Plan: Poked around locally (e.g., edited revisions to cause Herald to trigger), but hard to know if this will do what it's supposed to or not without deploying and seeing if it catches anything.

Reviewers: amckinley

Reviewed By: amckinley

Differential Revision: https://secure.phabricator.com/D20214
This commit is contained in:
epriestley 2019-02-25 19:13:55 -08:00
parent dc9aaa0fc2
commit 814e6d2de9
3 changed files with 24 additions and 15 deletions

View file

@ -208,15 +208,6 @@ final class DifferentialDiffEditor
return $adapter;
}
protected function didApplyHeraldRules(
PhabricatorLiskDAO $object,
HeraldAdapter $adapter,
HeraldTranscript $transcript) {
$xactions = array();
return $xactions;
}
private function updateDiffFromDict(DifferentialDiff $diff, $dict) {
$diff
->setSourcePath(idx($dict, 'sourcePath'))

View file

@ -186,15 +186,16 @@ abstract class HeraldAdapter extends Phobject {
return $this->appliedTransactions;
}
public function queueTransaction($transaction) {
final public function queueTransaction(
PhabricatorApplicationTransaction $transaction) {
$this->queuedTransactions[] = $transaction;
}
public function getQueuedTransactions() {
final public function getQueuedTransactions() {
return $this->queuedTransactions;
}
public function newTransaction() {
final public function newTransaction() {
$object = $this->newObject();
if (!($object instanceof PhabricatorApplicationTransactionInterface)) {
@ -205,7 +206,19 @@ abstract class HeraldAdapter extends Phobject {
'PhabricatorApplicationTransactionInterface'));
}
return $object->getApplicationTransactionTemplate();
$xaction = $object->getApplicationTransactionTemplate();
if (!($xaction instanceof PhabricatorApplicationTransaction)) {
throw new Exception(
pht(
'Expected object (of class "%s") to return a transaction template '.
'(of class "%s"), but it returned something else ("%s").',
get_class($object),
'PhabricatorApplicationTransaction',
phutil_describe_type($xaction)));
}
return $xaction;
}

View file

@ -3779,9 +3779,14 @@ abstract class PhabricatorApplicationTransactionEditor
$this->mustEncrypt = $adapter->getMustEncryptReasons();
$apply_xactions = $this->didApplyHeraldRules($object, $adapter, $xscript);
assert_instances_of($apply_xactions, 'PhabricatorApplicationTransaction');
$queue_xactions = $adapter->getQueuedTransactions();
return array_merge(
$this->didApplyHeraldRules($object, $adapter, $xscript),
$adapter->getQueuedTransactions());
array_values($apply_xactions),
array_values($queue_xactions));
}
protected function didApplyHeraldRules(