Skip to content
This repository has been archived by the owner on Apr 24, 2020. It is now read-only.

Commit

Permalink
improve error handling
Browse files Browse the repository at this point in the history
  • Loading branch information
Tabea David committed May 14, 2017
1 parent 17fc900 commit c8e514a
Showing 1 changed file with 7 additions and 13 deletions.
20 changes: 7 additions & 13 deletions src/Helpers/PwConnector.php
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
<?php namespace Wireshell\Helpers;

use ProcessWire\WireException;
use ProcessWire\WireHttp;
use ProcessWire\Template;
use Symfony\Component\Console\Command\Command as SymfonyCommand;
Expand Down Expand Up @@ -81,7 +82,7 @@ public function setTools() {
*/
public function checkForProcessWire() {
if (!getcwd()) {
$this->tools->writeError('Please check whether the current directory still exists.');
$this->tools->writeErrorAndExit('Please check whether the current directory still exists.');
exit(1);
}

Expand Down Expand Up @@ -176,21 +177,16 @@ protected function getCoreBranches($targetBranch = 'master') {
$branches = array();
$http = new WireHttp();
$http->setHeader('User-Agent', 'ProcessWireUpgrade');
$json = $http->get(self::branchesURL);
$data = $http->getJson(self::branchesURL);

if (!$json) {
if (!$data) {
$error = 'Error loading GitHub branches ' . self::branchesURL;
throw new \WireException($error);
$this->error($error);
return array();
$this->tools->writeErrorAndExit($error);
}

$data = json_decode($json, true);
if (!$data) {
$error = 'Error JSON decoding GitHub branches ' . self::branchesURL;
throw new \WireException($error);
$this->error($error);
return array();
$this->tools->writeErrorAndExit($error);
}

foreach ($data as $info) {
Expand All @@ -207,9 +203,7 @@ protected function getCoreBranches($targetBranch = 'master') {

if (!$json) {
$error = "Error loading sha `$targetBranch`.";
throw new \WireException($error);
$this->error($error);
return array();
$this->tools->writeErrorAndExit($error);
}

$name = $targetBranch;
Expand Down

0 comments on commit c8e514a

Please sign in to comment.