Skip to content

Commit a10324c

Browse files
committed
Include the file location in the error raise by the schema resource loader
1 parent 3e30ee3 commit a10324c

1 file changed

Lines changed: 13 additions & 3 deletions

File tree

apluslms-yamlidator/apluslms_yamlidator/schemas.py

Lines changed: 13 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import logging
22
from codecs import open
33
from collections import OrderedDict
4+
from importlib import import_module
45
from itertools import zip_longest
56
from json import dump as json_dumpf, loads as json_load
67
from os import (
@@ -9,6 +10,7 @@
910
)
1011
from os.path import (
1112
basename,
13+
dirname,
1214
exists,
1315
isdir,
1416
isfile,
@@ -79,10 +81,18 @@ def load():
7981
try:
8082
return parser(get_resource_text(module, filename))
8183
except Exception as error:
84+
refname = "'%s:%s'" % (module, filename)
85+
try:
86+
# try to look up the file location
87+
path = join(dirname(import_module(module).__file__), filename)
88+
except Exception:
89+
pass
90+
else:
91+
refname += " (%s)" % (path,)
8292
logger.error(
83-
"Read operation for a schema from a package '%s:%s' failed with %s: %s",
84-
module, filename, error.__class__.__name__, error)
85-
raise SchemaError("%s:%s" % (module, filename)) from error
93+
"Read operation for a schema from a package %s failed with %s: %s",
94+
refname, error.__class__.__name__, error)
95+
raise SchemaError(refname) from error
8696
return name, load
8797

8898

0 commit comments

Comments
 (0)