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

Better error messages #435

Merged
merged 33 commits into from
Aug 18, 2022
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
33 commits
Select commit Hold shift + click to select a range
3817110
Added URL to the message of HTTPError exceptions when loading an onto…
jesper-friis Aug 1, 2022
09a3460
Improved implementation of more verbose error messages
jesper-friis Aug 1, 2022
7639688
Merge branch 'master' into better-error-messages
jesper-friis Aug 2, 2022
5c36910
Merge branch 'master' into better-error-messages
jesper-friis Aug 4, 2022
bde56fa
Use prefix as arguemnt instead of namespace in get_by_label
francescalb Aug 11, 2022
8d1215a
Updated documentation with prefix for get_by_label
francescalb Aug 11, 2022
e84067c
Added automatic detection of prefix for the loaded ontology and tests
francescalb Aug 11, 2022
cb82c76
Corrected to that prefix actually cahcek for the prefix of the ontology
francescalb Aug 11, 2022
cf9d7a8
Added support for get_by_label('prefix:entity')
francescalb Aug 11, 2022
fcdf20a
Added test
jesper-friis Aug 11, 2022
d068c3b
Corrected import of HTTPError
jesper-friis Aug 11, 2022
224fb57
Updated docstring of get_by_label
francescalb Aug 12, 2022
ec306e9
Merge branch 'master' into flb/fix-prefix
francescalb Aug 16, 2022
2da03fe
Merge branch 'master' into better-error-messages
francescalb Aug 16, 2022
d76b91d
Added testonto to fixtures. This revealed a different issue that should
francescalb Aug 17, 2022
9ac54f2
Removed dependency on pydot
jesper-friis Aug 17, 2022
063e477
Apply suggestions from code review
jesper-friis Aug 17, 2022
7989cb6
Removed pydot from requirements
jesper-friis Aug 17, 2022
b0d64d3
Merge branch 'remove_pydot' into flb/fix-prefix
jesper-friis Aug 17, 2022
ed5686b
Updated so that label_annotations are taken care of even if load is not
francescalb Aug 17, 2022
2b21fcc
Merge branch 'flb/fix-prefix' of github.com:emmo-repo/EMMO-python int…
jesper-friis Aug 17, 2022
fe6a750
Removed old test_graph.py
jesper-friis Aug 17, 2022
cb570ac
Updated Ontology.get_unabbreviated_triples() to match changes in
jesper-friis Aug 17, 2022
909a645
Changes form pylint and blacken
jesper-friis Aug 17, 2022
0a834cc
Removed ontopy/ontograph.py
jesper-friis Aug 17, 2022
b597474
Removed docs for deleted ontograph
jesper-friis Aug 17, 2022
381cf0b
Fixed indentation in documentation
jesper-friis Aug 17, 2022
c86679d
Typo in docstring
jesper-friis Aug 17, 2022
e3dd4c0
Put prefix in init for Ontology and added emmo prefix tests
francescalb Aug 17, 2022
a1a5a43
Added asserts
jesper-friis Aug 17, 2022
fd0f69f
Merge branch 'flb/fix-prefix' into better-error-messages
jesper-friis Aug 17, 2022
14cdde6
Added test
jesper-friis Aug 17, 2022
fb34d4d
Merge branch 'master' into better-error-messages
francescalb Aug 18, 2022
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
35 changes: 27 additions & 8 deletions ontopy/ontology.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
from pathlib import Path
from collections import defaultdict
from collections.abc import Iterable
from urllib.request import HTTPError

import rdflib
from rdflib.util import guess_format
Expand Down Expand Up @@ -670,14 +671,32 @@ def getmtime(path):

self.loaded = False
with open(output, "rb") as handle:
return super().load(
only_local=True,
fileobj=handle,
reload=reload,
reload_if_newer=reload_if_newer,
format="rdfxml",
**kwargs,
)
try:
return super().load(
only_local=True,
fileobj=handle,
reload=reload,
reload_if_newer=reload_if_newer,
format="rdfxml",
**kwargs,
)
except HTTPError as exc: # Add url to HTTPError message
raise HTTPError(
url=exc.url,
code=exc.code,
msg=f"{exc.url}: {exc.msg}",
hdrs=exc.hdrs,
fp=exc.fp,
).with_traceback(exc.__traceback__)

except HTTPError as exc: # Add url to HTTPError message
raise HTTPError(
url=exc.url,
code=exc.code,
msg=f"{exc.url}: {exc.msg}",
hdrs=exc.hdrs,
fp=exc.fp,
).with_traceback(exc.__traceback__)

def save(
self,
Expand Down
11 changes: 9 additions & 2 deletions ontopy/utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

from rdflib import Graph, URIRef
from rdflib.util import guess_format
from rdflib.plugin import PluginException

import owlready2

Expand All @@ -26,9 +27,10 @@

# Format mappings: file extension -> rdflib format name
FMAP = {
"": "turtle",
"ttl": "turtle",
"n3": "ntriples",
"nt": "ntriples",
"ttl": "turtle",
"owl": "xml",
"rdfxml": "xml",
}
Expand Down Expand Up @@ -579,7 +581,12 @@ def recur(graph, outext):
)

graph = Graph()
graph.parse(input_ontology, format=fmt)
try:
graph.parse(input_ontology, format=fmt)
except PluginException as exc: # Add input_ontology to exception msg
raise PluginException(
f'Cannot load "{input_ontology}": {exc.msg}'
).with_traceback(exc.__traceback__)
francescalb marked this conversation as resolved.
Show resolved Hide resolved
graph.serialize(destination=output_ontology, format=output_format)
recur(graph, outext)

Expand Down
9 changes: 9 additions & 0 deletions tests/test_load.py
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,10 @@


def test_load(repo_dir: "Path", testonto: "Ontology") -> None:
import pytest

from ontopy import get_ontology
from ontopy.ontology import HTTPError

# Check that the defaults works
emmo = get_ontology("emmo").load() # ttl format
Expand All @@ -32,6 +35,12 @@ def test_load(repo_dir: "Path", testonto: "Ontology") -> None:
).load()
assert onto.Electrolyte.prefLabel.first() == "Electrolyte"

with pytest.raises(
HTTPError,
match="HTTP Error 404: https://emmo.info/non-existing/ontology: Not Found",
):
get_ontology("http://emmo.info/non-existing/ontology#").load()


def test_load_rdfs() -> None:
from ontopy import get_ontology
Expand Down