-
Notifications
You must be signed in to change notification settings - Fork 9
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
annotations: Crash on invalid move annotations #113
Comments
Hi @junghon3709 nice to meet you! I confirm the issue, here's what I did to reproduce based on your data on the terminal: Click here to expand for details# cat issue-113.py
from xiangqi_setup.file_formats.annofen import iterate_annofen_tokens, _escaped_annotation_names
with open('issue-113.annofen') as f:
list(iterate_annofen_tokens(f.read()))
# cat issue-113.annofen
v1 r1bakab1r/4c4/4c4/p1[n<a+1-3>]3p1p/9/3CC1P2/P1P1P3P/2N3N2/4A4/2BAK1B1R w - - 0 12
# python3.10 issue-113.py
Traceback (most recent call last):
File "[..]/xiangqi-setup/issue-113.py", line 4, in <module>
list(iterate_annofen_tokens(f.read()))
File "[..]/xiangqi-setup/xiangqi_setup/file_formats/annofen.py", line 92, in iterate_annofen_tokens
raise ValueError(f'Malformed annoFEN token: {character!r}')
ValueError: Malformed annoFEN token: '[' What is happening here is that "+1-3" is not a valid move to the eyes of xiangqi-setup and the way the parser works makes it end up with this admittedly unhelpful-to-humans error. For each supported move there is one SVG file, e.g. see this directory. If a move is legal to any of the pieces, it is supported, e.g. "a+1-2" is one out of eight for the knights/horses. The full list is this:
I have some hope that "+1-3" was in part a typo and that legal moves are enough for your use case? Then I would only need to improve the error message. I have some idea how to do that. What do you think, and what was your intention when trying "+1-3"? Best, Sebastian |
@junghon3709 what do you think? |
1 similar comment
@junghon3709 what do you think? |
I see now, I guess it makes sense to change the error message |
With #123 merged, the output would say…
…now. |
Version 2.2.0 with #123 merged released to GitHub and PyPI just now. |
Thank you for the change! |
I have the following annofen file:
v1 r1bakab1r/4c4/4c4/p1[n<a+1-2>]3p1p/9/3CC1P2/P1P1P3P/2N3N2/4A4/2BAK1B1R w - - 0 12
This renders successfully.
However, should I change the numbers in the arrows to:
v1 r1bakab1r/4c4/4c4/p1[n<a+1-3>]3p1p/9/3CC1P2/P1P1P3P/2N3N2/4A4/2BAK1B1R w - - 0 12
,an error message pops up:
The text was updated successfully, but these errors were encountered: