BPMNLint not exiting gracefully?

I’m currently building a Vue-based webapp based around BPMNLint. For that purpose I’m running an Express.JS backend where BPMNLint is located. Vue is sending a bpmn file to that server using axios.

This is my current backend setup:
image

Unfortunately, it’s returning both the result from the Linter but also an error.
image

I’m wondering what’s going on here. I could just return stdout in the response ofc since it seems to be working anyways, but it randomly erroring out just bothers me immensely.

Maybe someone here can help me out.

bpmnlint exits with 1 when any error occurs or when number of warnings exceeds the maximum value. This causes the exec function to report error (Child process | Node.js v19.0.1 Documentation. Note that this allows to easily adopt bpmnlint in your CI pipeline. It is also quite similar to how eslint works.

1 Like

Thanks for the reply.

It looks like I forgot how a Linter is supposed to work, even though I was using eslint in my project. Is there anything you can recommend in terms of response handling when using bpmnlint as a “standalone” application? Juggling the reply as a string might eventually work how I intend it to, but it’s far from elegant.

What you could do if you need to use bpmnlint like this is to parse the error messages. Have a look at this snippet:

import { exec } from 'child_process';

exec('node_modules/.bin/bpmnlint diagrams/diagram_1.bpmn', (error, stdout, stderr) => {
  if (!error) {
    return console.log('OK');
  }

  const trimmed = stdout.trim();
  const splitted = trimmed.split('\n');

  // file name is the first line and 2 last lines are the summary
  const problems = splitted.slice(1, -2).map(problem => problem.trim());

  console.log(JSON.stringify(problems, null, 2));

  // problems have a structure like this:
  const parsed = problems.map(problem => {
    const [ element, type, message, problemName ] = problem.split(/\s{2,}/);

    return {
      element,
      type,
      message,
      problemName
    };
  });

  console.log(JSON.stringify(parsed, null, 2));
});

which produces:

~/workspace/bpmn-io/linttest
❯ node .
[
  "StartEvent_1   error  Element is missing label/name  label-required",
  "Event_0qygfsq  error  Element is missing label/name  label-required"
]
[
  {
    "element": "StartEvent_1",
    "type": "error",
    "message": "Element is missing label/name",
    "problemName": "label-required"
  },
  {
    "element": "Event_0qygfsq",
    "type": "error",
    "message": "Element is missing label/name",
    "problemName": "label-required"
  }
]
1 Like