Hi there, we very occasionally (like 5% of the tim...
# pact-broker
t
Hi there, we very occasionally (like 5% of the time or less) get this error during our
pactPublish
step in CI (which uses the pact broker CLI) and im unsure what is causing it or how to solve, hoping someone could give me some ideas / lead me in the right direction please… please see thread for the error output
Copy code
Status: Downloaded newer image for pactfoundation/pact-cli:latest
Cannot change the content of the pact for OtacProviderService version bab2e3650bef58ceae679ca4c8e31b5ba62b0fad and provider OtacProviderService, as race conditions will cause unreliable results for can-i-deploy. Each pact must be published with a unique consumer version number. For more information see <https://docs.pact.io/go/versioning>
     {
       "response": {
         "headers": {
-          "Content-Type": "application/json; charset=UTF-8"
+          "Content-Type": "application/json;charset=UTF-8"
         }
       }
     },
     {
       "response": {
         "headers": {
-          "Content-Type": "application/json;charset=UTF-8"
+          "Content-Type": "application/json; charset=UTF-8"
         }
       }
     },
@@ -23,7 +23,7 @@
     {
       "response": {
         "headers": {
-          "Content-Type": "application/json; charset=UTF-8"
+          "Content-Type": "application/json;charset=UTF-8"
         }
       }
     },
the pacts havent changed so dont understand why that message appears
we follow git flow and this is on our PR / feature branches before being merged into
develop
the versioning on our consumer side follows the recommended git branch and short sha approach. the provider side is trunk based development and follows the same on PR branches (and once merged into main uses image version tags)
this is also on our consumer CI side not the provider 🤔
b
the pacts havent changed so dont understand why that message appears
There’s a whitespace change in the headers.
While that is semantically identical, unfortunately, the tool that generates the SHA from the pact content does not know that, and hence, it generates a different SHA, and considers that the pact has been changed.
Why your pact tests are generating pacts with headers with a space 95% of the time, and without a space 5% of the time, I have no idea.
Is there a dependency that is not pinned exactly, and maybe you’re getting an unpredictable version installed?
I can see that you haven’t pinned the pact CLI (pactfoundation/pact-cli:latest) and that’s a bit dangerous. One day, there will be a major release, and things will Break.
t
Thanks I will look to pin the pact cli. Not sure why the content type header changes as we dont set that explicitly in our tests, pact handles it
i now this morning just got this error instead on pactPublish step...
Copy code
/usr/lib/ruby/gems/3.0.0/gems/json-2.6.2/lib/json/common.rb:216:in `parse': 859: unexpected token at 'gex": "application/json(;\\\\s?charset=[\\\\w\\\\-]+)?" (JSON::ParserError)
          }
        },
        "status": 201
      }
    },
    {
      "description": "a request to reuse a Firebase token",
      "providerState": "there is a valid, reusable terminal configuration",
      "request": {
        "body": {
          "activation_code": "TK1474",
          "serial_number": "0822382308"
        },
        "method": "POST",
        "path": "/device/activate"
      },
      "response": {
        "body": {
          "token": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ8.eyJpc3MiOiJhZy1zdGFnaW5nLW1vYmlsZUBhcHBzcG90LmdzZXJ2aWNlYWNjb3VudC5jb20iLCJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImV4cCI6MTY0NjMxNjU5NiwiaWF0IjoxNjQ2MzEyOTk2LCJzdWIiOiJhZy1zdGFnaW5nLW1vYmlsZUBhcHBzcG90LmdzZXJ2aWNlYWNjb3VudC5jb20iLCJ1aWQiOiI0MTEwMDAzNyJ9.YQKzgFAmYGYi_ygkhBHVp6INGBsOuxGTwYFuwORovjx6uLM8Vs5m7DOa8BpLKfoZ9dSSm8XgsDeSsPH4c6C80eCm5kjJzhCYfI1_GL8uvkpWjqtT7jION7ybQZOoNMJ4rYTb4IyUOu06PG08VFBrt14uem-X_Kk_s-X_jnH2e81QHSvrM1ROCfDpkiDHic9S4op_zcaMPgKzC8vvJj5cY6Y11hPbhY2cb0z9BXIFql4S98rK96Hyw4JY2iWEt2dURtvYt-oyCWE4vP8uod3WEDZsrIc-3druPiZwbKp5Xx1S0MSuAwr8vs6mba5lkvreyoKNJAoxeHaJsnUigGl-Kg"
        },
        "headers": {
          "Content-Type": "application/json; charset=UTF-8"
        },
        "matchingRules": {
          "$.body.token": {
            "match": "regex",
            "regex": "eyJhbGciOiJSUzI1NiIsInR5cCI6IkpXVCJ8.eyJpc3MiOiJhZy1zdGFnaW5nLW1vYmlsZUBhcHBzcG90LmdzZXJ2aWNlYWNjb3VudC5jb20iLCJhdWQiOiJodHRwczovL2lkZW50aXR5dG9vbGtpdC5nb29nbGVhcGlzLmNvbS9nb29nbGUuaWRlbnRpdHkuaWRlbnRpdHl0b29sa2l0LnYxLklkZW50aXR5VG9vbGtpdCIsImV4cCI6MTY0NjMxNjU5NiwiaWF0IjoxNjQ2MzEyOTk2LCJzdWIiOiJhZy1zdGFnaW5nLW1vYmlsZUBhcHBzcG90LmdzZXJ2aWNlYWNjb3VudC5jb20iLCJ1aWQiOiI0MTEwMDAzNyJ9.YQKzgFAmYGYi_ygkhBHVp6INGBsOuxGTwYFuwORovjx6uLM8Vs5m7DOa8BpLKfoZ9dSSm8XgsDeSsPH4c6C80eCm5kjJzhCYfI1_GL8uvkpWjqtT7jION7ybQZOoNMJ4rYTb4IyUOu06PG08VFBrt14uem-X_Kk_s-X_jnH2e81QHSvrM1ROCfDpkiDHic9S4op_zcaMPgKzC8vvJj5cY6Y11hPbhY2cb0z9BXIFql4S98rK96Hyw4JY2iWEt2dURtvYt-oyCWE4vP8uod3WEDZsrIc-3druPiZwbKp5Xx1S0MSuAwr8vs6mba5lkvreyoKNJAoxeHaJsnUigGl-Kg"
          },
          "$.headers.Content-Type": {
            "match": "regex",
            "regex": "application/json(;\\\\s?charset=[\\\\w\\\\-]+)?"
          }
        },
        "status": 200
      }
    }
  ],
  "metadata": {
    "pact-jvm": {
      "version": "4.3.5"
    },
    "pactSpecification": {
      "version": "2.0.0"
    }
  },
  "provider": {
    "name": "OtacProviderService"
  }
}
'
b
I’m guessing that something in
"application/json(;\\\\s?charset=[\\\\w\\\\-]+)?"
is not parsing properly.
Not sure why the content type header changes as we dont set that explicitly in our tests
Could you be getting a different version of pact-jvm in some builds?
859: unexpected token at
Can you locate character 859?
t
pact-jvm is always
au.com.dius.pact.consumer:junit5:4.3.5
looking at the generated pacts file i think maybe i already made a change that could potentially fix it?
pact.json
as i dont see the
"application/json(;\\\\s?charset=[\\\\w\\\\-]+)?"
in there anywhere 😕 will keep an eye out to see if this issue pops up again, its been pretty random and infrequent
its possible the failed CI build that someone on my team shared with me probably needed rebasing or something to get latest pact changes that I made 🤔 and has looked to be fine after that fact
b
I'm glad it's working, but it is very annoying not to be able to work out why!