Skip to content

Commit b013b85

Browse files
author
Michael Babker
committed
Ensure all JHttp connections are wrapped in try/catch
1 parent 5ca5795 commit b013b85

File tree

3 files changed

+29
-7
lines changed

3 files changed

+29
-7
lines changed

administrator/components/com_patchtester/PatchTester/Controller/ApplyController.php

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,7 +35,7 @@ public function execute()
3535

3636
if ($model->apply($this->getInput()->getUint('pull_id')))
3737
{
38-
$msg = \JText::_('COM_PATCHTESTER_APPLY_OK');
38+
$msg = \JText::_('COM_PATCHTESTER_APPLY_OK');
3939
}
4040
else
4141
{

administrator/components/com_patchtester/PatchTester/Model/PullModel.php

Lines changed: 27 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -142,7 +142,14 @@ public function apply($id)
142142
);
143143
}
144144

145-
$pull = $github->pulls->get($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id);
145+
try
146+
{
147+
$pull = $github->pulls->get($this->getState()->get('github_user'), $this->getState()->get('github_repo'), $id);
148+
}
149+
catch (\Exception $e)
150+
{
151+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()));
152+
}
146153

147154
if (is_null($pull->head->repo))
148155
{
@@ -164,7 +171,14 @@ public function apply($id)
164171

165172
$transport = new \JHttp($options, $driver);
166173

167-
$patch = $transport->get($pull->diff_url)->body;
174+
try
175+
{
176+
$patch = $transport->get($pull->diff_url)->body;
177+
}
178+
catch (\Exception $e)
179+
{
180+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()));
181+
}
168182

169183
$files = $this->parsePatch($patch);
170184

@@ -177,26 +191,33 @@ public function apply($id)
177191
{
178192
if ($file->action == 'deleted' && !file_exists(JPATH_ROOT . '/' . $file->old))
179193
{
180-
throw new \RuntimeException(sprintf(\JText::_('COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S'), $file->old));
194+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_FILE_DELETED_DOES_NOT_EXIST_S', $file->old));
181195
}
182196

183197
if ($file->action == 'added' || $file->action == 'modified')
184198
{
185199
// If the backup file already exists, we can't apply the patch
186200
if (file_exists(JPATH_COMPONENT . '/backups/' . md5($file->new) . '.txt'))
187201
{
188-
throw new \RuntimeException(sprintf(\JText::_('COM_PATCHTESTER_CONFLICT_S'), $file->new));
202+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_CONFLICT_S', $file->new));
189203
}
190204

191205
if ($file->action == 'modified' && !file_exists(JPATH_ROOT . '/' . $file->old))
192206
{
193-
throw new \RuntimeException(sprintf(\JText::_('COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S'), $file->old));
207+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_FILE_MODIFIED_DOES_NOT_EXIST_S', $file->old));
194208
}
195209

196210
$url = 'https://raw.github.com/' . urlencode($pull->head->user->login) . '/' . urlencode($pull->head->repo->name)
197211
. '/' . urlencode($pull->head->ref) . '/' . $file->new;
198212

199-
$file->body = $transport->get($url)->body;
213+
try
214+
{
215+
$file->body = $transport->get($url)->body;
216+
}
217+
catch (\Exception $e)
218+
{
219+
throw new \RuntimeException(\JText::sprintf('COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB', $e->getMessage()));
220+
}
200221
}
201222
}
202223

administrator/components/com_patchtester/language/en-GB/en-GB.com_patchtester.ini

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ COM_PATCHTESTER_COMPONENT_DESC="Joomla! Patch Tester Configuration Values"
1313
COM_PATCHTESTER_COMPONENT_LABEL="Joomla! Patch Tester"
1414
COM_PATCHTESTER_CONFIGURATION="Joomla! Patch Tester Settings"
1515
COM_PATCHTESTER_CONFLICT_S="The patch could not be applied because it conflicts with a previously applied patch: %s"
16+
COM_PATCHTESTER_COULD_NOT_CONNECT_TO_GITHUB="Could not connect to GitHub with the following error: %s"
1617
COM_PATCHTESTER_ERROR_APPLIED_PATCHES="Cannot fetch data from GitHub while there are applied patches. Please revert those patches before continuing."
1718
COM_PATCHTESTER_ERROR_GITHUB_FETCH="Error retrieving pull requests from GitHub: %s"
1819
COM_PATCHTESTER_ERROR_INSERT_DATABASE="Error inserting pull request data into the database: %s"

0 commit comments

Comments
 (0)