Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Error messages are not always propagated through primer3_error #15

Open
msto opened this issue Sep 18, 2024 · 2 comments
Open

Error messages are not always propagated through primer3_error #15

msto opened this issue Sep 18, 2024 · 2 comments
Assignees

Comments

@msto
Copy link
Collaborator

msto commented Sep 18, 2024

primer3_error() fails to propagate errors when the logged error includes an equals sign.

When this occurs, the line is stored in primer3_results rather than error_lines.

Could we add stricter validation/parsing of the primer3 output, so underlying error messages are visible?

# contents of `primer3_results`
{'/Users/msto/.miniforge-x86/envs/gia_primer_design/bin/primer3_core:libprimer3.cc:5745, assertion (len >': ' 3) failed'}

# corresponding logged line
/Users/msto/.miniforge-x86/envs/gia_primer_design/bin/primer3_core:libprimer3.cc:5745, assertion (len >= 3) failed

def primer3_error(message: str) -> None:
"""Formats the Primer3 error and raises a ValueError."""
error_message = f"{message}: "
# add in any reported PRIMER_ERROR
if "PRIMER_ERROR" in primer3_results:
error_message += primer3_results["PRIMER_ERROR"]
# add in any error lines
if len(error_lines) > 0:
error_message += "\n".join(f"\t\t{e}" for e in error_lines)
# raise the exception now
raise ValueError(error_message)

if line == "=": # stop when we find the line just "="
break
elif line == "": # ignore empty lines
continue
elif "=" not in line: # error lines do not have the equals character in them, usually
error_lines.append(line)
else: # parse and store the result
key, value = line.split("=", maxsplit=1)
# Because Primer3 will emit both the input given and the output generated, we
# discard the input that is echo'ed back by looking for tags (keys)
# that do not match any Primer3InputTag
if not any(key == item.value for item in Primer3InputTag):
primer3_results[key] = value

@clintval
Copy link
Member

I agree! From the Zen of Python:

Errors should never pass silently.

I would like a way to see all logs from Primer3, perhaps by using the logging module and having the important logs set to INFO/WARNING and all the rest DEBUG.

@clintval
Copy link
Member

clintval commented Sep 23, 2024

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants