<#61 Handling error propagation during failed publ...
# pact-js-development
g
#61 Handling error propagation during failed publication Issue created by nu11try ### Software versions • OS: macOS Sequoia 15.4 (24E5206s) • Pact Node version: @pact-foundation/pact-node@10.18.0 @pact-foundation/pact@12.5.2 • Node Version: v20.18.1 ### Expected behaviour The pipeline is crashing ### Actual behaviour The pipeline does not crash ### Steps to reproduce When embedding a publication in ci/cd gitlab, there is a problem. If the publication fails, the pipeline is still considered "green" and this does not stop further steps. I use the following code in JS
Copy code
const publisher = require('@pact-foundation/pact-node');
const dotenv = require('dotenv');
const path = require('path');
const process = require('process');

dotenv.config();

const args = process.argv;

let version = '1.0.0';

args.forEach(arg => {
  if (arg.includes('--version')) version = arg.split('--version=')[1];
});

const opts = {
  consumerVersion: version,
  pactFilesOrDirs: [path.resolve(process.cwd(), 'contract_testing/pacts')],
  pactBrokerPassword: process.env.PACT_BROKER_PASSWORD,
  pactBrokerUsername: process.env.PACT_BROKER_USERNAME,
  pactBroker: process.env.PACT_BROKER_URL
};

publisher.publishPacts(opts)
I call it in the pipeline like this
Copy code
stages:
  - contract-tests
  - ...


contract-tests:
  stage: contract-tests
  image:
    name: ...
  script:
    - npm run test:pact
    - npm run publish:pact -- --version=$CI_COMMIT_TAG
  rules:
    - if: $SKIP_CONTRACT_TESTS == "true"
      when: never
    - if: $CI_COMMIT_TAG != null
And so I was able to achieve a pipeline crash so that the following steps do not pass
Copy code
publisher.publishPacts(opts)
  .then(() => {
    console.log('✅ Pacts successfully published');
  })
  .catch((error) => {
    console.error('❌ Publish failed:', error);
    process.exit(1);
  });
Fix -
process.exit(1);
Without fix [Image](https://private-user-images.githubusercontent.com/45148694/426561993-18df9461-9125-44b8-b474-6e2638f88baf.png?jwt=eyJhbGciOiJIUzI1NiIsInR5cCI6IkpXVCJ9.eyJpc3MiOiJnaXRodWIuY29tIiwiYXVkIjoicmF3LmdpdGh1YnVzZXJjb250ZW50LmNvbSIsImtleSI6ImtleTUiLCJleHAiOjE3NDI5OTIyMTAsIm5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BbXotU2lnbmF0dXJlPWJkMTQyMTFmMDY5MzI4ZThiNDhmNjRhYWRmZjY2NzI0NmNlMjMzOWY4Y2U3YjZiZmZhZGFmYTQ2NjM1M2ZiODMmWC1BbXotU2lnbmVkSGVhZGVycz1ob3N0In0.CL-0WNgKNV-VgpgUPjR59xIw20dZLsG1BI-U1a73xs0) pact-foundation/pact-js-cli