Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Handle errors by importing packages #81

Open
wants to merge 2 commits into
base: 0.4.x
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -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",
Expand Down
8 changes: 7 additions & 1 deletion src/Types/Harness/Repository/Repository.php
Original file line number Diff line number Diff line change
Expand Up @@ -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']));
}
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@a-ast i don't think we need the NULL check AND the flag?

Copy link
Collaborator

@dantleech dantleech Jan 28, 2022

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

but in anycase, I since added this sevice:

https://github.com/my127/workspace/blob/0.3.x/src/File/JsonLoader.php

which handles loading JSON in a way that can be better unit tested, so might make sense to refactor this class to use that....


$this->packages = array_merge($this->packages, $packages);
$this->sources[$k]['imported'] = true;
}
}
Expand Down