Skip to content

Commit

Permalink
addressing reviews
Browse files Browse the repository at this point in the history
  • Loading branch information
VGPReys committed Sep 18, 2024
1 parent 43e97e8 commit 5e11238
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 14 deletions.
10 changes: 8 additions & 2 deletions src/haddock/gear/known_cns_errors.py
Original file line number Diff line number Diff line change
Expand Up @@ -74,17 +74,23 @@ def find_cns_errors(cns_out_fpath: FilePath) -> Optional[KnownCNSError]:
Optional[KnownCNSError]
An exception for known CNS errors, with its hint on how to solve it!
"""
# Check for file extension
# Check for file extension to open it the appropriate way
if Path(cns_out_fpath).suffix == ".gz":
file_handle = gzip.open(cns_out_fpath, "rb")
else:
file_handle = open(cns_out_fpath, "rb")
# Read the file
try:
_find_cns_errors(file_handle, KNOWN_ERRORS, filepath=cns_out_fpath)
except KnownCNSError as err:
return err
else:
return None
# return the cause
return KnownCNSError(
"An unfortunate CNS error occured at exection time...",
f"Manually check the file `{cns_out_fpath}` to understand why!",
cns_out_fpath,
)


def _find_cns_errors(
Expand Down
13 changes: 6 additions & 7 deletions src/haddock/libs/libsubprocess.py
Original file line number Diff line number Diff line change
Expand Up @@ -132,11 +132,11 @@ def __init__(
self.cns_exec = cns_exec

def __repr__(self) -> str:
input_file = self.input_file
_input_file = self.input_file
if isinstance(self.input_file, str):
input_file = "IO Stream"
_input_file = "IO Stream"
return (
f"CNSJob({input_file}, {self.output_file}, "
f"CNSJob({_input_file}, {self.output_file}, "
f"envvars={self.envvars}, cns_exec={self.cns_exec})"
)

Expand Down Expand Up @@ -262,13 +262,12 @@ def contains_cns_stdout_error(out: bytes) -> bool:
# Decode end of STDOUT
# Search in last 24000 characters (300 lines * 80 characters)
sout = out[-24000:].split(bytes(os.linesep, "utf-8"))
print(sout)
print(type(sout))
print()
# Reverse loop on lines (read backward)
for bytes_line in reversed(sout):
line = bytes_line.decode("utf-8")
if " ^^^^^^^" in line:
# This checks for an unknown CNS error
# triggered when CNS is about to crash due to internal error
if "^^^^^" in line:
return True
# Check if a known error is found
elif any([error in line for error in KNOWN_CNS_ERRORS.keys()]):
Expand Down
6 changes: 1 addition & 5 deletions src/haddock/modules/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -304,11 +304,7 @@ def export_io_models(self, faulty_tolerance=0):
if detected_errors := find_all_cns_errors(self.path):
_msg += linesep
for error in detected_errors.values():
_msg += (
# f'An error was detected in {len(error["files"])} files'
# f'({",".join(error["files"][:3])}...).{linesep}'
f'{str(error["error"])}{linesep}'
)
_msg += f'{str(error["error"])}{linesep}'
# Show final error message
self.finish_with_error(_msg)

Expand Down

0 comments on commit 5e11238

Please sign in to comment.