@recaptime-dev's working patches + fork for Phorge, a community fork of Phabricator. (Upstream dev and stable branches are at upstream/main and upstream/stable respectively.) hq.recaptime.dev/wiki/Phorge
phorge phabricator
1
fork

Configure Feed

Select the types of activity you want to include in your feed.

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

+32 -1
resources/builtin/image-100x100.png

This is a binary file and will not be displayed.

resources/builtin/image-220x220.png

This is a binary file and will not be displayed.

resources/builtin/image-280x210.png

This is a binary file and will not be displayed.

+12 -1
src/applications/files/controller/PhabricatorFileTransformController.php
··· 54 54 if (isset($xforms[$transform])) { 55 55 $xform = $xforms[$transform]; 56 56 if ($xform->canApplyTransform($file)) { 57 - $xformed_file = $xforms[$transform]->applyTransform($file); 57 + try { 58 + $xformed_file = $xforms[$transform]->applyTransform($file); 59 + } catch (Exception $ex) { 60 + // TODO: Provide a diagnostic mode to surface these to the viewer. 61 + 62 + // In normal transform mode, we ignore failures and generate a 63 + // default transform instead. 64 + } 65 + } 66 + 67 + if (!$xformed_file) { 68 + $xformed_file = $xform->getDefaultTransform($file); 58 69 } 59 70 } 60 71
+16
src/applications/files/transform/PhabricatorFileThumbnailTransform.php
··· 71 71 } 72 72 } 73 73 74 + public function getDefaultTransform(PhabricatorFile $file) { 75 + $x = (int)$this->dstX; 76 + $y = (int)$this->dstY; 77 + $name = 'image-'.$x.'x'.nonempty($y, $x).'.png'; 78 + 79 + $params = array( 80 + 'name' => $name, 81 + 'canCDN' => true, 82 + ); 83 + 84 + $root = dirname(phutil_get_library_root('phabricator')); 85 + $data = Filesystem::readFile($root.'/resources/builtin/'.$name); 86 + 87 + return PhabricatorFile::newFromFileData($data, $params); 88 + } 89 + 74 90 }
+4
src/applications/files/transform/PhabricatorFileTransform.php
··· 7 7 abstract public function canApplyTransform(PhabricatorFile $file); 8 8 abstract public function applyTransform(PhabricatorFile $file); 9 9 10 + public function getDefaultTransform(PhabricatorFile $file) { 11 + return null; 12 + } 13 + 10 14 public function generateTransforms() { 11 15 return array($this); 12 16 }