# Buggy code
def index_pass(self):
    def safe_update_index(path):
        chunk_id = path.rsplit("/", 1)[-1]
        if len(chunk_id) != STRLEN_CHUNKID:
            return
        for c in chunk_id:
            if c not in hexdigits:
                return
        try:
            self.update_index(path)
            self.successes += 1
            self.logger.debug("Updated %s", path)
        except OioNetworkException as exc:
            self.errors += 1
            self.logger.warn("ERROR while updating %s: %s", path, exc)
        except Exception:
            self.errors += 1
            self.logger.exception("ERROR while updating %s", path)
        self.total_since_last_reported += 1

    def report(tag):
        total = self.errors + self.successes
        now = time.time()
        elapsed = (now - start_time) or 0.000001
        self.logger.info(
            "%(tag)s=%(current_time)s "
            "elapsed=%(elapsed).02f "
            "pass=%(pass)d "
            "errors=%(errors)d "
            "chunks=%(nb_chunks)d %(c_rate).2f/s"
            % {
                "tag": tag,
                "current_time": datetime.fromtimestamp(int(now)).isoformat(),
                "pass": self.passes,
                "errors": self.errors,
                "nb_chunks": total,
                "c_rate": self.total_since_last_reported / (now - self.last_reported),
                "elapsed": elapsed,
            }
        )
        self.last_reported = now
        self.total_since_last_reported = 0

    start_time = time.time()
    self.last_reported = start_time
    self.errors = 0
    self.successes = 0

    paths = paths_gen(self.volume)
    report("started")
    for path in paths:
        safe_update_index(path)
        self.chunks_run_time = ratelimit(
            self.chunks_run_time, self.max_chunks_per_second
        )
        now = time.time()
        if now - self.last_reported >= self.report_interval:
            report("running")
    report("ended")


# Traceback (VolumeException)
11573 7F920C7A0730 log ERROR ERROR while updating /var/lib/oio/sds/OPENIO/rawx-0/7BD/7BDE49669C6616A0656097C6544923F1BB0EE711A23D9D18B7D23071997AB9F7
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/oio/blob/indexer.py", line 65, in safe_update_index
self.update_index(path)
File "/usr/lib/python2.7/dist-packages/oio/blob/indexer.py", line 132, in update_index
**data)
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 298, in chunk_push
json=body, headers=headers)
File "/usr/lib/python2.7/dist-packages/oio/common/utils.py", line 586, in ensure_headers_wrapper
return func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/oio/common/utils.py", line 596, in ensure_request_id_wrapper
return func(*args, **kwargs)
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 273, in _rdir_request
uri = self._make_uri(action, volume)
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 264, in _make_uri
rdir_host = self._get_rdir_addr(volume_id)
File "/usr/lib/python2.7/dist-packages/oio/rdir/client.py", line 261, in _get_rdir_addr
raise VolumeException('No rdir assigned to volume %s' % volume_id)
VolumeException: No rdir assigned to volume 172.18.0.1:6004

# Fixed code
def index_pass(self):
    def safe_update_index(path):
        chunk_id = path.rsplit("/", 1)[-1]
        if len(chunk_id) != STRLEN_CHUNKID:
            return
        for c in chunk_id:
            if c not in hexdigits:
                return
        try:
            self.update_index(path)
            self.successes += 1
            self.logger.debug("Updated %s", path)
        except OioNetworkException as exc:
            self.errors += 1
            self.logger.warn("ERROR while updating %s: %s", path, exc)
        except VolumeException as exc:
            self.errors += 1
            self.logger.error("Cannot index %s: %s", path, exc)
            # All chunks of this volume are indexed in the same service,
            # no need to try another chunk, it will generate the same
            # error. Let the upper level retry later.
            raise
        except Exception:
            self.errors += 1
            self.logger.exception("ERROR while updating %s", path)
        self.total_since_last_reported += 1

    def report(tag):
        total = self.errors + self.successes
        now = time.time()
        elapsed = (now - start_time) or 0.000001
        self.logger.info(
            "%(tag)s=%(current_time)s "
            "elapsed=%(elapsed).02f "
            "pass=%(pass)d "
            "errors=%(errors)d "
            "chunks=%(nb_chunks)d %(c_rate).2f/s"
            % {
                "tag": tag,
                "current_time": datetime.fromtimestamp(int(now)).isoformat(),
                "pass": self.passes,
                "errors": self.errors,
                "nb_chunks": total,
                "c_rate": self.total_since_last_reported / (now - self.last_reported),
                "elapsed": elapsed,
            }
        )
        self.last_reported = now
        self.total_since_last_reported = 0

    start_time = time.time()
    self.last_reported = start_time
    self.errors = 0
    self.successes = 0

    paths = paths_gen(self.volume)
    report("started")
    for path in paths:
        safe_update_index(path)
        self.chunks_run_time = ratelimit(
            self.chunks_run_time, self.max_chunks_per_second
        )
        now = time.time()
        if now - self.last_reported >= self.report_interval:
            report("running")
    report("ended")