Skip to content

Commit

Permalink
fix: improper error handling of errors (#33)
Browse files Browse the repository at this point in the history
* fix: improper error handling of errors

* fix: check indices
  • Loading branch information
beckermr authored Dec 2, 2024
1 parent 519bef7 commit c975aae
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 12 deletions.
2 changes: 1 addition & 1 deletion .pre-commit-config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -16,7 +16,7 @@ repos:
- id: end-of-file-fixer
- id: trailing-whitespace
- repo: https://github.com/astral-sh/ruff-pre-commit
rev: v0.7.2
rev: v0.8.1
hooks:
- id: ruff
args: [ --fix ]
Expand Down
50 changes: 41 additions & 9 deletions conda_forge_feedstock_ops/container_utils.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,8 @@
import os
import pprint
import subprocess
from typing import Callable, Iterable, Optional
from collections.abc import Iterable
from typing import Callable, Optional

from ._version import __version__

Expand Down Expand Up @@ -179,15 +180,46 @@ def run_container_operation(
)

if "error" in ret:
ret_str = (
ret["error"]
.split("(", maxsplit=1)[1]
.rsplit(")", maxsplit=1)[0]
.encode("raw_unicode_escape")
.decode("unicode_escape")
)
if (
"(" in ret["error"]
and ")" in ret["error"]
and len(ret["error"].split("(", maxsplit=1)) > 1
):
ret_str = (
ret["error"]
.split("(", maxsplit=1)[1]
.rsplit(")", maxsplit=1)[0]
.encode("raw_unicode_escape")
.decode("unicode_escape")
)
ename = (
ret["error"]
.split("(")[0]
.strip()
.encode("raw_unicode_escape")
.decode("unicode_escape")
)
elif ":" in ret["error"] and len(ret["error"].split(":", maxsplit=1)) > 1:
ret_str = (
ret["error"]
.split(":", maxsplit=1)[1]
.strip()
.encode("raw_unicode_escape")
.decode("unicode_escape")
)
ename = (
ret["error"]
.split(":")[0]
.strip()
.encode("raw_unicode_escape")
.decode("unicode_escape")
)
else:
ret_str = ret["error"]
ename = "<could not be parsed"

raise ContainerRuntimeError(
error=f"Error running '{' '.join(args)}' in container - error {ret['error'].split('(')[0]} raised:\n{ret_str}",
error=f"Error running '{' '.join(args)}' in container - error {ename} raised:\n{ret_str}",
args=args,
cmd=pprint.pformat(cmd),
returncode=res.returncode,
Expand Down
3 changes: 1 addition & 2 deletions conda_forge_feedstock_ops/json.py
Original file line number Diff line number Diff line change
Expand Up @@ -3,7 +3,6 @@
from typing import (
IO,
Any,
Set,
)

import rapidjson as json
Expand All @@ -13,7 +12,7 @@

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

Expand Down

0 comments on commit c975aae

Please sign in to comment.