Handle unknown document IDs gracefully
On at least the ecp-dbg
branch, requesting an unknown document leads to an unintuitive error:
> python3 -m dcc view P1600312
Enter username for login.ligo.org: sean.leavey
Enter password for login 'sean.leavey':
Traceback (most recent call last):
File "/home/sean/Workspace/Repositories/dcc-api/dcc/patterns.py", line 30, in validate
self.root = ET.fromstring(self.content)
File "/usr/lib/python3.5/xml/etree/ElementTree.py", line 1333, in XML
parser.feed(text)
xml.etree.ElementTree.ParseError: not well-formed (invalid token): line 46, column 7
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/usr/lib/python3.5/runpy.py", line 184, in _run_module_as_main
"__main__", mod_spec)
File "/usr/lib/python3.5/runpy.py", line 85, in _run_code
exec(code, run_globals)
File "/home/sean/Workspace/Repositories/dcc-api/dcc/__main__.py", line 302, in <module>
main()
File "/home/sean/Workspace/Repositories/dcc-api/dcc/__main__.py", line 297, in main
func(func.parse_args(args))
File "/home/sean/Workspace/Repositories/dcc-api/dcc/__main__.py", line 130, in __call__
record = fetch_dcc_record(archive, args.dccid)
File "/home/sean/Workspace/Repositories/dcc-api/dcc/__main__.py", line 82, in fetch_dcc_record
return archive.fetch_record(dccid)
File "/home/sean/Workspace/Repositories/dcc-api/dcc/record.py", line 138, in fetch_record
record = DccRecord._fetch(self.fetcher, dcc_number)
File "/home/sean/Workspace/Repositories/dcc-api/dcc/record.py", line 681, in _fetch
parser.validate()
File "/home/sean/Workspace/Repositories/dcc-api/dcc/patterns.py", line 56, in validate
raise UnknownDccErrorException()
dcc.patterns.UnknownDccErrorException: An unknown error occurred; please report this to the developers
The solution is probably to parse the error document - which is not XML but rather HTML - and look for "This document does not exist", then throw a more appropriate error.