geocoder-php / geocoder-php/Geocoder
Bug when use chain and GeoIp2 at first position with cache
Nobody has claimed this yet.
- Dominant language
- PHP
- Stars
- 4k
- Forks
- 525
- Avg merge
- 8m
- Merged PRs (30d)
- 1
Description
GeoIp2 return empty collection and save it in cache after that next providers(custom) load from cache empty collection instead of using his code
$result = json_decode($this->executeQuery($address));
if (null === $result) {
return new AddressCollection([]);
}
$result = json_decode(''); //NULL
private function executeQuery(string $address): string
{
$uri = sprintf('file://geoip?%s', $address);
try {
$result = $this->adapter->getContent($uri);
} catch (AddressNotFoundException $e) {
return '';
} catch (AuthenticationException $e) {
throw new InvalidCredentials(
$e->getMessage(),
$e->getCode(),
$e
);
} catch (OutOfQueriesException $e) {
throw new QuotaExceeded(
$e->getMessage(),
$e->getCode(),
$e
);
}
return $result;
}
I think there should not be return '';, but there should be fatal
public function geocodeQuery(GeocodeQuery $query): Collection
{
foreach ($this->providers as $provider) {
try {
$result = $provider->geocodeQuery($query);
if (!$result->isEmpty()) {
return $result;
}
} catch (\Throwable $e) {
$this->log(
'alert',
sprintf('Provider "%s" could geocode address: "%s".', $provider->getName(), $query->getText()),
['exception' => $e]
);
}
}
return new AddressCollection();
}
\Geocoder\Provider\Chain\Chain::geocodeQuery now always return empty collectioon \Geocoder\Model\AddressCollection();
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with the GeoIp2 provider's executeQuery and geocodeQuery methods, then trace how Chain::geocodeQuery handles an empty collection from the first provider and cache reads for later providers. Reproduce a chain with GeoIp2 first and a custom provider second; done means an empty GeoIp2 response no longer prevents the later provider from being used, with the intended error behavior verified.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- php
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Mostly clear
- Newbie friendliness
- 35/100