Hacktoberfest 2026: the issues maintainers tagged for October, open and beginner-friendly. Browse Hacktoberfest issues

Bug when use chain and GeoIp2 at first position with cache

Open
#936 3 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

Assessment

Difficulty
4/5
Estimated time
3-5 days
Newbie friendliness
35/100
Issue type
Bug
Clarity
Mostly clear
Activity status
Stale
Tech stack
php
Domain
backend

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.

Description

question

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();

Dominant language
PHP
Stars
4k
Forks
525
Avg merge
8m
Merged PRs (30d)
1

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

More from geocoder-php/Geocoder

All issues in geocoder-php/Geocoder

Similar issues

More PHP issues

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.