1
0
Fork 0
mirror of https://we.phorge.it/source/phorge.git synced 2024-12-22 21:40:55 +01:00

Open editor from stack trace

Summary:
I've considered that user may have set editor but not checked out Phabricator repositories.
But stack trace is useful mainly for developers.

Test Plan:
Click on path in Unhandled Exception.
Repeat with disabled editor.

Reviewers: epriestley

Reviewed By: epriestley

CC: aran

Differential Revision: https://secure.phabricator.com/D2107
This commit is contained in:
vrana 2012-04-04 17:53:16 -07:00
parent 09172a1937
commit d1b7059a2d
5 changed files with 34 additions and 29 deletions

View file

@ -445,8 +445,14 @@ class AphrontDefaultApplicationConfiguration
$class = phutil_escape_html(get_class($ex));
$message = phutil_escape_html($ex->getMessage());
$user = $this->getRequest()->getUser();
if (!$user) {
// If we hit an exception very early, we won't have a user.
$user = new PhabricatorUser();
}
if (PhabricatorEnv::getEnvConfig('phabricator.show-stack-traces')) {
$trace = $this->renderStackTrace($ex->getTrace());
$trace = $this->renderStackTrace($ex->getTrace(), $user);
} else {
$trace = null;
}
@ -457,12 +463,6 @@ class AphrontDefaultApplicationConfiguration
$trace.
'</div>';
$user = $this->getRequest()->getUser();
if (!$user) {
// If we hit an exception very early, we won't have a user.
$user = new PhabricatorUser();
}
$dialog = new AphrontDialogView();
$dialog
->setTitle('Unhandled Exception ("'.$class.'")')
@ -525,20 +525,17 @@ class AphrontDefaultApplicationConfiguration
));
}
private function renderStackTrace($trace) {
private function renderStackTrace($trace, PhabricatorUser $user) {
$libraries = PhutilBootloader::getInstance()->getAllLibraries();
// TODO: Make this configurable?
$host = 'https://secure.phabricator.com';
$path = 'https://secure.phabricator.com/diffusion/%s/browse/master/src/';
$browse = array(
'arcanist' =>
$host.'/diffusion/ARC/browse/master/src/',
'phutil' =>
$host.'/diffusion/PHU/browse/master/src/',
'phabricator' =>
$host.'/diffusion/P/browse/master/src/',
$callsigns = array(
'arcanist' => 'ARC',
'phutil' => 'PHU',
'phabricator' => 'P',
);
$rows = array();
@ -565,14 +562,22 @@ class AphrontDefaultApplicationConfiguration
}
if ($file) {
if (isset($browse[$lib])) {
if (isset($callsigns[$lib])) {
$attrs = array(
'href' => $user->loadEditorLink(
'/src/'.$relative,
$part['line'],
$callsigns[$lib]),
'title' => $file,
);
if (!$attrs['href']) {
$attrs['href'] = sprintf($path, $callsigns[$lib]).
$relative.'$'.$part['line'];
$attrs['target'] = '_blank';
}
$file_name = phutil_render_tag(
'a',
array(
'href' => $browse[$lib].$relative.'$'.$part['line'],
'title' => $file,
'target' => '_blank',
),
$attrs,
phutil_escape_html($relative));
} else {
$file_name = phutil_render_tag(

View file

@ -256,7 +256,8 @@ final class DifferentialChangesetListView extends AphrontView {
$changeset->getAbsoluteRepositoryPath($this->diff, $repository),
'/');
$line = 1; // TODO: get first changed line
$editor_link = $user->loadEditorLink($path, $line, $repository);
$callsign = $repository->getCallsign();
$editor_link = $user->loadEditorLink($path, $line, $callsign);
if ($editor_link) {
$meta['editor'] = $editor_link;
} else {

View file

@ -200,7 +200,7 @@ final class DifferentialDiffTableOfContentsView extends AphrontView {
$editor_link = $this->user->loadEditorLink(
implode(' ', $paths),
1, // line number
$this->repository);
$this->repository->getCallsign());
if ($editor_link) {
$editor_link = phutil_render_tag(
'a',

View file

@ -221,7 +221,8 @@ final class DiffusionBrowseFileController extends DiffusionController {
$path = $drequest->getPath();
$line = 1;
$editor_link = $user->loadEditorLink($path, $line, $repository);
$callsign = $repository->getCallsign();
$editor_link = $user->loadEditorLink($path, $line, $callsign);
if (!$editor_link) {
return null;
}

View file

@ -413,16 +413,14 @@ final class PhabricatorUser extends PhabricatorUserDAO {
return $preferences;
}
public function loadEditorLink($path,
$line,
PhabricatorRepository $repository) {
public function loadEditorLink($path, $line, $callsign) {
$editor = $this->loadPreferences()->getPreference(
PhabricatorUserPreferences::PREFERENCE_EDITOR);
if ($editor) {
return strtr($editor, array(
'%f' => phutil_escape_uri($path),
'%l' => phutil_escape_uri($line),
'%r' => phutil_escape_uri($repository->getCallsign()),
'%r' => phutil_escape_uri($callsign),
));
}
}