ArniDagur / python-adblock

Brave's adblock library in Python
https://pypi.org/project/adblock/
Apache License 2.0
58 stars 4 forks source link

Expose the different Rust errors as Python exceptions #44

Closed ArniDagur closed 3 years ago

ArniDagur commented 3 years ago

Currently, users have to parse the error string, which is not ideal. See https://github.com/qutebrowser/qutebrowser/commit/7da7110bc73170647d4c48520f639e3fd2e2e802

try:
  self._engine.deserialize_from_file(str(self._cache_path))
except ValueError as e:
  if str(e) != "DeserializationError":
      # All Rust exceptions get turned into a ValueError by
      # python-adblock
      raise
  message.error("Reading adblock filter data failed (corrupted data?). "
                "Please run :adblock-update.")
The-Compiler commented 3 years ago

Thanks! Handling this in an unified way is a bit of a pain for qutebrowser now, but it was the right thing to do and I suppose at some point we can drop support for < 0.5.0.