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

handle errors/execptions when summarize sgfs files #534

Merged

Conversation

fuhaoda
Copy link
Contributor

@fuhaoda fuhaoda commented Aug 5, 2021

passed test on the damaged sgfs files

game = sgf.Sgf_game.from_bytes(sgf_string)
winner = game.get_winner()
except:
print ("A sgf string is damaged, and its record has been skipped!")
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This is not ideal, you should almost never try to catch all exceptions in python, since it will even catch the user pressing ctrl-c or trying to terminate the program. Instead, catch only the specific exception(s) that from_bytes will actually raise.

Additionally, this error message could be a bit more helpful. Ideally _add_a_single_sgf_string should be augmented to have a "debug_source" argument, which contains the file name and/or line number, so that the print message can display more helpful info to the user about trying to find where the problem is.

Copy link
Contributor Author

@fuhaoda fuhaoda Aug 5, 2021

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! I just updated this based on the comment. I made it more specific on the error as value error. Since there will be a string passed into _add_a_single_sgf_string, the only non-terminating exception should be ValueError. The solution has been tested on the damaged files.
In addition, I also made the print out the error as a colored message so that people can see more clear on where the error from.

@lightvector lightvector merged commit e3931fa into lightvector:master Aug 7, 2021
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

Successfully merging this pull request may close these issues.

2 participants