Scripts: be more robust when parsing test logs#21160
Conversation
There was a problem hiding this comment.
Pull request overview
This PR improves the robustness of the test log parsing script by adding exception handling to prevent crashes when encountering unexpected log formats. The script previously failed with a StopIteration error when parsing logs with unexpected content.
Changes:
- Added try-except block to handle
StopIterationgracefully when parsing test failure blocks - Logs a warning message when encountering unexpected end of logs instead of crashing
💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.
| error_line = parse_log_line(next(lines)) | ||
| except StopIteration: | ||
| LOGGER.warning("Encountered unexpected end of logs while parsing failure block.") | ||
| break |
There was a problem hiding this comment.
The variable filename_match may be undefined when accessed at this line. If StopIteration is caught at line 134, the code breaks out of the try block, but filename_match will not have been assigned if the exception occurred before line 127 or if no match was found before the exception. This will cause an UnboundLocalError. The continue statement should be used instead of break in the exception handler to skip to the next iteration of the outer for loop.
| break | |
| continue |
|
@RasmusWL Do you think you will find time to review this at some point? Or should the CODEOWNERS file be changed? |
RasmusWL
left a comment
There was a problem hiding this comment.
Do you think you will find time to review this at some point?
Thanks. If it works on your end, let's do it 👍
Or should the CODEOWNERS file be changed?
I initially wrote this, but haven't had to use it for more than a year. if you want to take ownership, that would be great 💪
(don't really remember how anything works 😂)
The script was falling over on this log, I believe because of the unexpected
getSignatureParameterNameline in this section:The terminal output was as follow:
I asked copilot to fix it and it added this try-except block so that at least other patches could be produced. Now when I run the script I get this output:
(And then a C# patch failed to apply, but I assume that's unrelated.)