Skip to content

Commit c975aae

Browse files
authored
fix: improper error handling of errors (#33)
* fix: improper error handling of errors * fix: check indices
1 parent 519bef7 commit c975aae

File tree

3 files changed

+43
-12
lines changed

3 files changed

+43
-12
lines changed

.pre-commit-config.yaml

+1-1
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ repos:
1616
- id: end-of-file-fixer
1717
- id: trailing-whitespace
1818
- repo: https://github.com/astral-sh/ruff-pre-commit
19-
rev: v0.7.2
19+
rev: v0.8.1
2020
hooks:
2121
- id: ruff
2222
args: [ --fix ]

conda_forge_feedstock_ops/container_utils.py

+41-9
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,8 @@
33
import os
44
import pprint
55
import subprocess
6-
from typing import Callable, Iterable, Optional
6+
from collections.abc import Iterable
7+
from typing import Callable, Optional
78

89
from ._version import __version__
910

@@ -179,15 +180,46 @@ def run_container_operation(
179180
)
180181

181182
if "error" in ret:
182-
ret_str = (
183-
ret["error"]
184-
.split("(", maxsplit=1)[1]
185-
.rsplit(")", maxsplit=1)[0]
186-
.encode("raw_unicode_escape")
187-
.decode("unicode_escape")
188-
)
183+
if (
184+
"(" in ret["error"]
185+
and ")" in ret["error"]
186+
and len(ret["error"].split("(", maxsplit=1)) > 1
187+
):
188+
ret_str = (
189+
ret["error"]
190+
.split("(", maxsplit=1)[1]
191+
.rsplit(")", maxsplit=1)[0]
192+
.encode("raw_unicode_escape")
193+
.decode("unicode_escape")
194+
)
195+
ename = (
196+
ret["error"]
197+
.split("(")[0]
198+
.strip()
199+
.encode("raw_unicode_escape")
200+
.decode("unicode_escape")
201+
)
202+
elif ":" in ret["error"] and len(ret["error"].split(":", maxsplit=1)) > 1:
203+
ret_str = (
204+
ret["error"]
205+
.split(":", maxsplit=1)[1]
206+
.strip()
207+
.encode("raw_unicode_escape")
208+
.decode("unicode_escape")
209+
)
210+
ename = (
211+
ret["error"]
212+
.split(":")[0]
213+
.strip()
214+
.encode("raw_unicode_escape")
215+
.decode("unicode_escape")
216+
)
217+
else:
218+
ret_str = ret["error"]
219+
ename = "<could not be parsed"
220+
189221
raise ContainerRuntimeError(
190-
error=f"Error running '{' '.join(args)}' in container - error {ret['error'].split('(')[0]} raised:\n{ret_str}",
222+
error=f"Error running '{' '.join(args)}' in container - error {ename} raised:\n{ret_str}",
191223
args=args,
192224
cmd=pprint.pformat(cmd),
193225
returncode=res.returncode,

conda_forge_feedstock_ops/json.py

+1-2
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,6 @@
33
from typing import (
44
IO,
55
Any,
6-
Set,
76
)
87

98
import rapidjson as json
@@ -13,7 +12,7 @@
1312

1413
def default(obj: Any) -> Any:
1514
"""For custom object serialization."""
16-
if isinstance(obj, Set):
15+
if isinstance(obj, set):
1716
return {"__set__": True, "elements": sorted(obj)}
1817
raise TypeError(repr(obj) + " is not JSON serializable")
1918

0 commit comments

Comments
 (0)