fix: NgxParserBaseException.__str__ raises TypeError when lineno is None#119
Open
gaoflow wants to merge 1 commit into
Open
fix: NgxParserBaseException.__str__ raises TypeError when lineno is None#119gaoflow wants to merge 1 commit into
gaoflow wants to merge 1 commit into
Conversation
When lineno is None, __str__ used self.args (a 3-tuple) with a 2-placeholder format string, causing TypeError: not all arguments converted during string formatting. Use the named attributes directly so both branches format correctly. Fixes nginxinc#93.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
NgxParserBaseException.__str__raisesTypeError: not all arguments converted during string formattingwhenlinenoisNone.The else-branch used
self.args(a 3-tuple of(strerror, filename, lineno)) with a 2-placeholder format string:This is triggered whenever an error is caught without a line number, e.g. through
crossplane.formatter.format()when the underlying parser error carrieslineno=None, or from any code that wraps a non-NgxParserexception and passeslineno=Noneexplicitly.Fix
Use the named instance attributes directly in both branches, so the tuple passed to
%always matches the format string:Fixes #93.
Tests
Three new tests in
tests/test_analyze.pycover:str()with a valid line number (regression guard)str()withlineno=None(the previously crashing case)NgxParserSyntaxError)All 48 tests pass.
This pull request was prepared with the assistance of AI, under my direction and review.