From 0f011fe4559080fd9ebc8330d602f11d1fe7f324 Mon Sep 17 00:00:00 2001 From: Andrey Astakhov Date: Mon, 12 Apr 2021 12:55:02 +0200 Subject: [PATCH 1/2] Add explicit dependency on ext-json because of json functions used. --- composer.json | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/composer.json b/composer.json index e1ff8e96..6f7b6663 100644 --- a/composer.json +++ b/composer.json @@ -11,7 +11,8 @@ "symfony/expression-language": "^4.4", "symfony/finder": "^4.4", "symfony/yaml": "^4.4", - "twig/twig": "^2.13" + "twig/twig": "^2.13", + "ext-json": "*" }, "require-dev": { "phpunit/phpunit": "^9.5", From 9a7b859078682b2da405d121fd6878301a888666 Mon Sep 17 00:00:00 2001 From: Andrey Astakhov Date: Mon, 12 Apr 2021 12:56:10 +0200 Subject: [PATCH 2/2] Allow package import fail with an expicit error message --- src/Types/Harness/Repository/Repository.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Types/Harness/Repository/Repository.php b/src/Types/Harness/Repository/Repository.php index 668263d8..91756564 100644 --- a/src/Types/Harness/Repository/Repository.php +++ b/src/Types/Harness/Repository/Repository.php @@ -75,7 +75,13 @@ private function importPackagesFromSources() continue; } - $this->packages = array_merge($this->packages, json_decode(file_get_contents($source['url']), true)); + $packages = json_decode(file_get_contents($source['url']), true, JSON_THROW_ON_ERROR); + + if ($packages === null) { + throw new Exception(sprintf('Response of %s can\'t be decoded as json.', $source['url'])); + } + + $this->packages = array_merge($this->packages, $packages); $this->sources[$k]['imported'] = true; } }