0

I am facing a weird error that I don't know how to handle

so an object is created from a method

procesed_sequences = sequence.find(seq_in_list)

This procesed_sequences return an object:

In normal condition, when we call for loop on this procesed_sequences:

for seq in procesed_sequences:
    record.append(seq)

It is giving an error at a specific seq

File "sequence.py", line 290, in run for seq in procesed_sequences:
File "/home/.local/lib/python3.6/site-packages/sequence_finder.py", line 34, in look_sequence
    seq_start = row.index("1")  # start of sequence
ValueError: '1' is not in list

if I try to print the seq object

for seq in procesed_sequences:
    print(seq)

It will print all the seq object until the problematic one and fail

so I thought using try and except

try:
   record.append(seq)
except:
   print(f"This sequence is giving error in")
   print(e)

However, the try and except doesn't work, it seems the error happened at the try part when seq object is generated, now there is no way for me to go access the sequence script atm, how do I just ask seq object to not get call in the procesed_sequences if it's giving error

Thank you

10
  • What is the error? A traceback might help Commented May 15, 2021 at 4:13
  • I add the error on the top, but at the moment there is no way for me to access the sequence_finder.py since I don't have permission, and I am wondering why try and except doesn't work when calling object Commented May 15, 2021 at 4:18
  • “procesed_sequences” is a generator, the error is being raised during the iteration over that generator. You would need to wrap the for loop in the try/except to catch the error Commented May 15, 2021 at 4:21
  • 1
    If you can edit the generator then you could catch the exception and continue after handling it somehow. Once a generator has exited by raising an exception there is no way to continue it Commented May 15, 2021 at 4:29
  • 1
    The package is supplied by another team in your company? I suggest raising a bug/issue with the team that maintains that package Commented May 15, 2021 at 4:51

1 Answer 1

1

Norman can you please put a try and except block inside the find function mentioned below from the sequence.py file.

procesed_sequences = sequence.find(seq_in_list)

It's not failing in the try-except block in the above is because it's been running on append operation. If possible please share the code for find function from the squence.py file. Problem seems to lie there

Sign up to request clarification or add additional context in comments.

8 Comments

Thanks for the response, yea unfortunately I don't have access to that script at the moment due to permission error, that's why I am trying to fix at the wrapper script level
The problem is that your generator is doing a lazy evaluation and creating a seq object at the time of appending to the list and that's why it's failing at that time. Do you have any inbuilt logger inside the restricted file? It would be really difficult to try debugging the error from the wrapper class
yea at the moment I am not trying to debug, just trying to skip that seq object with problem and want to know if there is any other way to do so
One thing you can do is that create a counter variable and print the index of processed_sequence list at which it is failing and hardcode inside the code to skip that. Try it and let me know if that works
I think that will work, but I can't just do that for this one sample, I think best option for me right now is to skip this sample and let the upper management decide what they can do before I get permission to tackle the bug
|

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.