Skip to content

Commit

Permalink
Fixes #33: Better error reporting when output does not contain json. (#…
Browse files Browse the repository at this point in the history
…46)

* Fixes #33: Better error reporting when output does not contain json.
* Fix appveyor (only php 7.3 supported now)
  • Loading branch information
greg-1-anderson authored Aug 12, 2019
1 parent 32ffa26 commit 1ee818b
Show file tree
Hide file tree
Showing 3 changed files with 12 additions and 7 deletions.
7 changes: 4 additions & 3 deletions appveyor.yml
Original file line number Diff line number Diff line change
Expand Up @@ -24,10 +24,11 @@ install:
- git clone -q https://github.com/acquia/DevDesktopCommon.git #For tar, cksum, ...
- SET PATH=%APPVEYOR_BUILD_FOLDER%/DevDesktopCommon/bintools-win/msys/bin;%PATH%
- SET PATH=C:\Program Files\MySql\MySQL Server 5.7\bin\;%PATH%
- choco search php --exact --all-versions -r
#Install PHP per https://blog.wyrihaximus.net/2016/11/running-php-unit-tests-on-windows-using-appveyor-and-chocolatey/
- ps: Set-Service wuauserv -StartupType Manual
- ps: appveyor-retry cinst --ignore-checksums -y php --version ((choco search php --exact --all-versions -r | select-string -pattern $Env:php_ver_target | Select-Object -first 1) -replace '[php|]','')
- cd c:\tools\php71
- cd c:\tools\php73
- copy php.ini-production php.ini

- echo extension_dir=ext >> php.ini
Expand All @@ -44,7 +45,7 @@ install:
- echo extension=php_pdo_sqlite.dll >> php.ini
- echo extension=php_pgsql.dll >> php.ini
- echo extension=php_gd2.dll >> php.ini
- SET PATH=C:\tools\php71;%PATH%
- SET PATH=C:\tools\php73;%PATH%
#Install Composer
- cd %APPVEYOR_BUILD_FOLDER%
#- appveyor DownloadFile https://getcomposer.org/composer.phar
Expand All @@ -61,4 +62,4 @@ test_script:
# environment variables
environment:
global:
php_ver_target: 7.1
php_ver_target: 7.3
10 changes: 7 additions & 3 deletions src/ProcessBase.php
Original file line number Diff line number Diff line change
Expand Up @@ -178,10 +178,14 @@ public function getOutputAsJson()
// Revert of doubled backslashes.
$output = preg_replace('#\\\\{2}#', '\\', $output);
}
$output = $this->removeNonJsonJunk($output);
$json = json_decode($output, true);
$sanitizedOutput = $this->removeNonJsonJunk($output);
$json = json_decode($sanitizedOutput, true);
if (!isset($json)) {
throw new \InvalidArgumentException('Unable to decode output into JSON.');
$msg = 'Unable to decode output into JSON: ' . json_last_error_msg();
if (json_last_error() == JSON_ERROR_SYNTAX) {
$msg .= "\n\n$output";
}
throw new \InvalidArgumentException($msg);
}
return $json;
}
Expand Down
2 changes: 1 addition & 1 deletion tests/SiteProcessTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -227,7 +227,7 @@ public function siteProcessJsonTestValues()
'LINUX',
],
[
'Unable to decode output into JSON.',
"Unable to decode output into JSON: Syntax error\n\nNo json data here",
'No json data here',
NULL,
],
Expand Down

0 comments on commit 1ee818b

Please sign in to comment.