pact-foundation / pact_broker-client

A Ruby and CLI client for the Pact Broker. Publish and retrieve pacts and verification results.
MIT License
69 stars 48 forks source link

NameError on publish #73

Closed wilkinsleung0712 closed 4 years ago

wilkinsleung0712 commented 4 years ago

Hi team, i had experienced NameError when publish to pact broker.

 "dependencies": {
    "@pact-foundation/pact": "^9.12.0",
    "axios": "^0.19.0",
    "faker": "^5.1.0",
    "kafkajs": "^1.14.0",
    "uuid": "^8.3.0"
  },

publish code is same as example repo

onst child_process = require('child_process');
const exec = command =>
  child_process
    .execSync(command)
    .toString()
    .trim()
const path = require("path")
const { Publisher } = require("@pact-foundation/pact")
const branch = exec("git rev-parse --abbrev-ref HEAD")
// publish to local docker
// const opts = {
//   pactBroker: 'localhost:9292',
//   consumerVersion: '1',
//   pactFilesOrDirs: ['./pacts'],
// };
const gitSha =  exec("git rev-parse HEAD")
const opts = {
  pactFilesOrDirs: [path.resolve(process.cwd(), "pacts")],
  pactBroker: "https://test.pact.dius.com.au",
  pactBrokerUsername: "dXfltyFMgNOFZAxr8io9wJ37iUpY42M",
  pactBrokerPassword: "O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1",
  consumerVersion: gitSha,
  tags: [branch],
}
new Publisher(opts).publishPacts().then(() => {
  console.log("Pact contract publishing complete!")
  console.log("")
  console.log("Head over to https://test.pact.dius.com.au/ and login with")
  console.log("=> Username: dXfltyFMgNOFZAxr8io9wJ37iUpY42M")
  console.log("=> Password: O5AIZWxelWbLvqMd8PkAVycBJh2Psyg1")
  console.log("to see your published contracts.")
})
  .catch(e => {
    console.log("Pact contract publishing failed: ", e)
  })
$ node publish.ts
[2020-09-29T01:04:15.001Z]  INFO: pact-node@10.10.1/45810 on wilkinsliang: Publishing Pacts to Broker
[2020-09-29T01:04:15.002Z]  INFO: pact-node@10.10.1/45810 on wilkinsliang: Publishing pacts to broker at: https://test.pact.dius.com.au
[2020-09-29T01:04:15.316Z]  WARN: pact-node@10.10.1/45810 on wilkinsliang: Pact exited with code 1.
[2020-09-29T01:04:15.317Z] ERROR: pact-node@10.10.1/45810 on wilkinsliang: 
    Could not publish pact:
    /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/broker.rb:59:in `rescue in publish': uninitialized constant PactBroker::Client::Error (NameError)
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/broker.rb:55:in `publish'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/app/pact-broker.rb:28:in `<main>'

Pact contract publishing failed:  Error: /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/broker.rb:59:in `rescue in publish': uninitialized constant PactBroker::Client::Error (NameError)
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/broker.rb:55:in `publish'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/command.rb:27:in `run'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/invocation.rb:126:in `invoke_command'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor.rb:387:in `dispatch'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/thor-0.20.3/lib/thor/base.rb:466:in `start'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/vendor/ruby/2.2.0/gems/pact_broker-client-1.27.0/lib/pact_broker/client/cli/custom_thor.rb:15:in `start'
        from /dummydir/consumer/node_modules/@pact-foundation/pact-node/standalone/linux-x64-1.86.0/pact/lib/app/pact-broker.rb:28:in `<main>'

    at ChildProcess.<anonymous> (/dummydir/consumer/node_modules/@pact-foundation/pact-node/src/publisher.js:72:40)
    at Object.onceWrapper (events.js:421:26)
    at ChildProcess.emit (events.js:326:22)
    at maybeClose (internal/child_process.js:1051:16)
    at Process.ChildProcess._handle.onexit (internal/child_process.js:287:5)
bethesque commented 4 years ago

Can you upgrade to the latest version. This was fixed in 72eb796ada10bc9deb83804057c5a4b96612ceef which was released in 1.28.4.

bethesque commented 4 years ago

You will probably need to force an upgrade of pact-node.