Skip to content

Commit f1f8179

Browse files
committed
Make CLR errors more informative
1 parent 3a5c4e2 commit f1f8179

File tree

3 files changed

+1215
-1
lines changed

3 files changed

+1215
-1
lines changed

clr_loader/util/__init__.py

Lines changed: 33 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,36 @@
1+
class ClrError(Exception):
2+
def __init__(self, hresult, name=None, message=None, comment=None):
3+
self.hresult = hresult
4+
self.name = name
5+
self.message = message
6+
self.comment = comment
7+
8+
def __str__(self):
9+
if self.message:
10+
return f"{hex(self.hresult)}: {self.name} => {self.message}"
11+
elif self.name:
12+
return f"{hex(self.hresult)}: {self.name}"
13+
else:
14+
return f"{hex(self.hresult)}"
15+
16+
17+
def __repr__(self):
18+
return f"<ClrError {str(self)}>"
19+
20+
121
def check_result(err_code):
222
if err_code < 0:
3-
raise RuntimeError(hex(err_code & 0xFFFFFFFF))
23+
hresult = err_code & 0xFFFFFFFF
24+
25+
error = get_coreclr_error(hresult)
26+
if not error:
27+
error = get_hostfxr_error(hresult)
28+
29+
if not error:
30+
error = ClrError(hresult)
31+
32+
raise error
33+
434

35+
from .coreclr_errors import get_coreclr_error
36+
from .hostfxr_errors import get_hostfxr_error

0 commit comments

Comments
 (0)