complement icon indicating copy to clipboard operation
complement copied to clipboard

Prevent re-interpreting errors if they have placeholder patterns

Open anoadragon453 opened this issue 8 months ago • 0 comments

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 avatar Jun 03 '25 17:06 anoadragon453