mirror of
https://we.phorge.it/source/phorge.git
synced 2024-12-18 19:40:55 +01:00
Make modular transforms handle exceptions gracefully
Summary: Ref T7707. Ref T2479. Ref T5258. The thumbnailing code is some of the only code in the codebase which doesn't use exceptions to handle errors. I'm going to convert it to use exceptions; make sure they do something reasonable at top level. Strategy here is: - By default, we just fall back to a placeholder image if anything goes wrong. - Later, I'll likely add a "debug" workflow from the new "Transforms" UI which will surface the specific exception instead (the code can't really raise any interesting exceptions right now). Test Plan: Faked an exception and saw some reasonable default images. Reviewers: btrahan Reviewed By: btrahan Subscribers: epriestley Maniphest Tasks: T5258, T2479, T7707 Differential Revision: https://secure.phabricator.com/D12809
This commit is contained in:
parent
c998e44b5a
commit
65ff40844b
6 changed files with 32 additions and 1 deletions
BIN
resources/builtin/image-100x100.png
Normal file
BIN
resources/builtin/image-100x100.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 993 B |
BIN
resources/builtin/image-220x220.png
Normal file
BIN
resources/builtin/image-220x220.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
BIN
resources/builtin/image-280x210.png
Normal file
BIN
resources/builtin/image-280x210.png
Normal file
Binary file not shown.
After Width: | Height: | Size: 1.3 KiB |
|
@ -54,7 +54,18 @@ final class PhabricatorFileTransformController
|
|||
if (isset($xforms[$transform])) {
|
||||
$xform = $xforms[$transform];
|
||||
if ($xform->canApplyTransform($file)) {
|
||||
try {
|
||||
$xformed_file = $xforms[$transform]->applyTransform($file);
|
||||
} catch (Exception $ex) {
|
||||
// TODO: Provide a diagnostic mode to surface these to the viewer.
|
||||
|
||||
// In normal transform mode, we ignore failures and generate a
|
||||
// default transform instead.
|
||||
}
|
||||
}
|
||||
|
||||
if (!$xformed_file) {
|
||||
$xformed_file = $xform->getDefaultTransform($file);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
|
@ -71,4 +71,20 @@ final class PhabricatorFileThumbnailTransform
|
|||
}
|
||||
}
|
||||
|
||||
public function getDefaultTransform(PhabricatorFile $file) {
|
||||
$x = (int)$this->dstX;
|
||||
$y = (int)$this->dstY;
|
||||
$name = 'image-'.$x.'x'.nonempty($y, $x).'.png';
|
||||
|
||||
$params = array(
|
||||
'name' => $name,
|
||||
'canCDN' => true,
|
||||
);
|
||||
|
||||
$root = dirname(phutil_get_library_root('phabricator'));
|
||||
$data = Filesystem::readFile($root.'/resources/builtin/'.$name);
|
||||
|
||||
return PhabricatorFile::newFromFileData($data, $params);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -7,6 +7,10 @@ abstract class PhabricatorFileTransform extends Phobject {
|
|||
abstract public function canApplyTransform(PhabricatorFile $file);
|
||||
abstract public function applyTransform(PhabricatorFile $file);
|
||||
|
||||
public function getDefaultTransform(PhabricatorFile $file) {
|
||||
return null;
|
||||
}
|
||||
|
||||
public function generateTransforms() {
|
||||
return array($this);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue