bpmn-io / bpmn-auto-layout

Layout BPMN diagrams, generating missing DI information.
https://bpmn-io.github.io/bpmn-auto-layout/
52 stars 41 forks source link

`TypeError: Cannot read properties of undefined (reading 'filter')` #43

Closed corocoto closed 2 months ago

corocoto commented 8 months ago

Describe the Bug

I refactored example.js imports. In the end, I run the script to see how the layoutProcess function will set di elements for the bpmn structure. But unfortunately, it throws an error:

file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:707
    const startingElements = flowElements.filter(el => {
                                          ^

TypeError: Cannot read properties of undefined (reading 'filter')
    at Layouter.createGridLayout (file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:707:43)
    at Layouter.handlePlane (file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:694:25)
    at Layouter.createGridLayout (file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:732:14)
    at Layouter.handlePlane (file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:694:25)
    at Layouter.layoutProcess (file:///home/corocoto/Documents/Github/bpmn-auto-layout/dist/index.esm.js:688:10)
    at async file:///home/corocoto/Documents/Github/bpmn-auto-layout/example.js:65:28

Steps to Reproduce

  1. Open a test project in the Replit
  2. Click onto the "Run" button

Expected Behavior

The script will print a new bpmn structure into a console and also will write it into layouted.bpmn file.

Environment

corocoto commented 8 months ago

Additional information

Maybe it will be helpful to represent and visualize this schema. So, it looks like the next one:

1) The main structure:

diagram

2) subProcess (Task_01g18mq ) internal structure:

subProcess-internal

nikku commented 8 months ago

I dropped the unmaintained example via https://github.com/bpmn-io/bpmn-auto-layout/commit/fbb021dcc759c2df089610b335e5bc9766ada54a.

If it was not working (layouting fails) then I'd assume it would be great to reproduce the error in a failing test case. We could take it from there.

corocoto commented 8 months ago

I'd assume it would be great to reproduce the error in a failing test case

@nikku, done! https://github.com/bpmn-io/bpmn-auto-layout/pull/44

nikku commented 8 months ago

Thanks. A good start to fix this, some day, maybe.

till-stadtler commented 3 months ago

Hi! I am currently testing the BPMN copilot prototype. I came across this error when the AI model returned an empty subprocess as part of the process XML.

This part of the code is the issue:

createGridLayout(root) {
    const grid = new Grid();

    const flowElements = root.flowElements;

    const startingElements = flowElements.filter(el => {
      return !isConnection(el) && !isBoundaryEvent(el) && (!el.incoming || el.length === 0);
    });
    ...
}

When entering the scope of the empty subprocess, no flowElements exist. The issue might be solved by checking for existing flowElements, and simply returning the grid (?) if none exist. But there might be more issues down the line which might require more checks.

It would be great to have this issue fixed soon! Otherwise my tests will fail as soon as the AI model returns an empty subprocess! :/