Skip to content

Commit c816d53

Browse files
committed
Update coreclr_errors script
1 parent 4cbf668 commit c816d53

1 file changed

Lines changed: 18 additions & 5 deletions

File tree

clr_loader/util/coreclr_errors.py

Lines changed: 18 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -26,15 +26,24 @@ def get_coreclr_error(hresult: int) -> Optional[ClrError]:
2626
from xml.etree import ElementTree
2727

2828
if len(argv) < 2:
29-
url = "https://raw.githubusercontent.com/dotnet/coreclr/master/src/inc/corerror.xml"
29+
# Download corerror.xml if it was not passed as an argument
30+
31+
from urllib.request import urlopen
32+
3033
print(
31-
f"Please download corerror.xml from {url} and pass as an argument to this script"
34+
"No filename passed, downloading corerror.xml from the dotnet/coreclr repository..."
3235
)
33-
exit(1)
36+
url = "https://raw.githubusercontent.com/dotnet/coreclr/master/src/inc/corerror.xml"
37+
f = urlopen(url)
38+
else:
39+
f = open(argv[1], "r")
3440

35-
tree = ElementTree.parse(argv[1])
41+
tree = ElementTree.parse(f)
3642

37-
print(f"Parsed {argv[1]}, updating {__file__}...")
43+
if hasattr(f, "close"):
44+
f.close()
45+
46+
print(f"Parsed data, updating {__file__}...")
3847

3948
marker = "# == Autogenerated from corerror.xml =="
4049

@@ -51,7 +60,11 @@ def get_coreclr_error(hresult: int) -> Optional[ClrError]:
5160
for row in tree.findall(".//HRESULT"):
5261
try:
5362
numeric_value = int(row.attrib["NumericValue"], base=16)
63+
except ValueError:
64+
print("Failed to parse numeric value:", row.attrib["NumericValue"])
65+
continue
5466

67+
try:
5568
for child in row:
5669
if child.text:
5770
text = child.text.strip(' "')

0 commit comments

Comments
 (0)