Skip to content

Prevent re-interpreting errors if they have placeholder patterns #785

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

Draft
wants to merge 1 commit into
base: main
Choose a base branch
from

Conversation

anoadragon453
Copy link
Member

In my out-of-tree Complement tests, I was seeing instances of %!F(MISSING) appearing in my Complement logs when a matcher failed. It turns out that this was due to things that looked like printf placeholders existing in my test data. Specifically, the URL https://127.0.0.1:6560/oauth2/authorize?response_type=code&client_id=test_idp_client_id&redirect_uri=http%3A%2F%2F127.0.0.1%3A8008%2F_synapse%2Fclient%2Foidc%2Fcallback&scope=read%3Auser has things like %3A and %2F in it as there's a url-encoded URL in a query parameter.

When the test failed and Complement went to print this out to me, it ended up re-interpreting the string with t.Fatalf, yet providing no arguments for the placeholders. This then results in the %3A being replaced by %!A(MISSING) as go could not find a corresponding variable.

In this PR, I've replaced calls to t.Fatalf that had no argument with t.Fatal instead. The result is below.

Before:

my_test.go:336: MatchResponse got status 200 want 302 - http://127.0.0.1:33236/_matrix/client/v3/auth/m.login.sso/fallback/web?session=IZAVpTVdxHUnboGcTiBNnkJf => <!DOCTYPE html>
<!-- snip -->
<a href="https://127.0.0.1:6560/oauth2/authorize?response_type=code&amp;client_id=test_idp_client_id&amp;redirect_uri=http%!A(MISSING)%!F(MISSING)%!F(MISSING)127.0.0.1%!A(MISSING)8008%!F(MISSING)_synapse%!F(MISSING)client%!F(MISSING)oidc%!F(MISSING)callback&amp;scope=read%!A(MISSING)user&amp;state=DUMv68wL2LWVjc3FMMjFECdtUNVtiv&amp;nonce=YxvUxS2iU7NwC32i2XTJ4MOVwhROctDy" class="primary-button">

After:

<a href="https://127.0.0.1:6560/oauth2/authorize?response_type=code&amp;client_id=test_idp_client_id&amp;redirect_uri=http%3A%2F%2F127.0.0.1%3A8008%2F_synapse%2Fclient%2Foidc%2Fcallback&amp;scope=read%3Auser&amp;state=Cgc5nQkiLZX4ehOeAeQgFhf4vt9yzs&amp;nonce=gjr8eoj5AHdQ2m5W2N16s7W1yk5YCLsN" class="primary-button">

This works in my use case, though I'm not entirely sure if this would affect any other output. Notably, I think one would still have the same issue if they tried to use must.NotError, as that requires the use of ct.Fatalf. Feedback welcome.

Pull Request Checklist

@anoadragon453 anoadragon453 requested review from a team as code owners June 3, 2025 17:16
@anoadragon453 anoadragon453 marked this pull request as draft June 3, 2025 18:52
Copy link
Member

@kegsay kegsay left a comment

Choose a reason for hiding this comment

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

Good catch, thanks!

@erikjohnston erikjohnston removed the request for review from a team June 25, 2025 13:00
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