Fix issue pester#2062 "Stacktrace is not filtered in non-english system languages"
PR Summary
Fix issue #2062 "Stacktrace is not filtered in non-english system languages"
When using StackTraceverbosity = 'Filtered', pester internals are filtered from the stack trace using regex matching. However, Windows stack trace are localized depending on the language of the OS. The words "At" and "Line" which can be translated (or not) depending on the language of the system.
This PR introduce an heuristic-like solution in ConvertTo-FailureLines function :
We throw an exception on purpose, then catch it in order to detect the localized strings of the stack trace. We then feed these localized strings back to the regex for filtering pester internals.
PR Checklist
- [X] PR has meaningful title
- [X] Summary describes changes
- [ ] PR is ready to be merged
- If not, use the arrow next to
Create Pull Requestto mark it as a draft. PR can be markedReady for reviewwhen it's ready.
- If not, use the arrow next to
- [ ] Tests are added/update (if required)
- [ ] Documentation is updated/added (if required)
FYI, this is a work in progress.
I do not know if this is the right approach to fix this issue. Would love some feedback about my proposed change.
Also, i think building the module without -Inline will not work because of the code at lines 540-548
Thanks for looking into this!
Last year I intended to simply replace at|line with \S+ as I assume all languages use a single word and the same placements. Unfortunately I had some issues getting multiple samples last year to verify that assumption and include as tests.
While this PR is clever and more precise, it follows the same assumptions. I wonder if it might be unnecessary complex?
A bonus with your approach is that we could technically localize the added tracelines for PesterAssertionFailed, though I'm not sure if we should since the translation might not be great.
Also, i think building the module without -Inline will not work because of the code at lines 540-548
I don't follow. Wouldn't the same word-replacements apply there as well? Could you elaborate?
Hi,
Last year I intended to simply replace
at|linewith\S+as I assume all languages use a single word and the same placements. Unfortunately I had some issues getting multiple samples last year to verify that assumption and include as tests.While this PR is clever and more precise, it follows the same assumptions. I wonder if it might be unnecessary complex?
From my experience, localization of technical messages (such as Stack Traces) on Windows can be quite inconsistent depending on the language/culture of the system. And it's not only applied to words but also to punctuation according to local conventions.
For example, on a French(France) machine, the ":" is preceded by a non-breakable space...
(That's why I used \s* when trying to extract the Filename with the regex).
I may be able to gather stack traces for a few different languages and share them here if that can be useful to you.
Also, i think building the module without -Inline will not work because of the code at lines 540-548
I don't follow. Wouldn't the same word-replacements apply there as well? Could you elaborate?
I have pushed a new commit to my branch that modifies the code inside these lines.
However, unlike the code at lines 556-557, this if($true) "PESTER_BUILD" block does not contains special code related to non-Windows systems.
I currently don't have the means to test on non-Windows system so my concern may be a non-issue though.
👍
I may be able to gather stack traces for a few different languages and share them here if that can be useful to you.
Would be nice to have as part of tests.
this
if($true)"PESTER_BUILD" block does not contains special code related to non-Windows systems.
No need. That part uses the folderpath in the pattern, so will always have the correct slash/backslash. 🙂
There is another PR #2391 implementing this in hopefully the most reliable way, and we cannot repro the issue. If you know how to make the stack traces show up in different language or how to test this on en-us system that would be awesome contribution to the other PR.