pistazie / cdk-dia

Automated diagrams of CDK provisioned infrastructure
MIT License
895 stars 38 forks source link

Failed to generate diagram - Error: Unable to calculate a unique id for an empty set of components #30

Open RobertoTorino opened 2 years ago

RobertoTorino commented 2 years ago

npx cdk-dia fails with the following error:

% npx cdk-dia

Failed to generate diagram - Error: Unable to calculate a unique id for an empty set of components
/usr/local/lib/node_modules/cdk-dia/node_modules/@aws-cdk/core/lib/private/uniqueid.js:33
        throw new Error('Unable to calculate a unique id for an empty set of components');
              ^
Error: Unable to calculate a unique id for an empty set of components
    at makeUniqueId (/usr/local/lib/node_modules/cdk-dia/node_modules/@aws-cdk/core/lib/private/uniqueid.js:33:15)
    at AwsEdgeResolver.findUniqueResourceId (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:83:44)
    at /usr/local/lib/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:55:47
    at DiagramComponent.subTreeFindComponentRec (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/component/component.js:137:13)
    at DiagramComponent.subTreeFindComponent (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/component/component.js:134:21)
    at /usr/local/lib/node_modules/cdk-dia/dist/src/diagram/component/component.js:140:23
    at Array.map (<anonymous>)
    at DiagramComponent.subTreeFindComponentRec (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/component/component.js:139:40)
    at DiagramComponent.subTreeFindComponent (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/component/component.js:134:21)
    at AwsEdgeResolver.findTargetComponent (/usr/local/lib/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:54:47)

workaround for now: go to: /usr/local/lib/node_modules/cdk-dia/node_modules/@aws-cdk/core/lib/private

change this:

function makeUniqueId(components) {
    components = components.filter(x => x !== HIDDEN_ID);
    if (components.length === 0) {
        throw new Error('Unable to calculate a unique id for an empty set of components');
    }

to this:

function makeUniqueId(components) {
    components = components.filter(x => x !== HIDDEN_ID);
    if (components.length < 0) {
        throw new Error('Unable to calculate a unique id for an empty set of components');
    }
pistazie commented 2 years ago

Before cdk-dia calls makeUniqueId it checks, that the components array isn't empty (if (pathParts.length === 0) return false).

Therefore, I guess this line filters the component, creating an empty array.

Could you share some CDK code to help reproduce the issue?

I would prefer trying to solve the issue downstream, then copying the non-exported const HIDDEN_ID = 'Default'; variable to CDK-Dia.

bestickley commented 1 year ago

Hi, I've also run into this issue. I cannot share my codebase, but I can show you command output.

cdk --app "pnpm tsx src/pipeline/pipeline-app.ts" ls
...
ss-pipeline
cross-region-stack-349310182770:us-east-1
ss-pipeline/ss-dev/Nextjs-ss-dev-EdgeFn-c8fa5
ss-pipeline/ss-dev/data
ss-pipeline/ss-dev/waf
ss-pipeline/ss-dev/analysis
ss-pipeline/ss-dev/ui

Then when I run: pnpm cdk-dia --exclude ss-pipeline I get:

Failed to generate diagram - Error: Unable to calculate a unique id for an empty set of components
/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/@aws-cdk+core@1.203.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk_snfrqglsb5l5t6w6kv7z6d6qki/node_modules/@aws-cdk/core/lib/private/uniqueid.js:33
        throw new Error('Unable to calculate a unique id for an empty set of components');
              ^

Error: Unable to calculate a unique id for an empty set of components
    at makeUniqueId (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/@aws-cdk+core@1.203.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk_snfrqglsb5l5t6w6kv7z6d6qki/node_modules/@aws-cdk/core/lib/private/uniqueid.js:33:15)
    at AwsEdgeResolver.findUniqueResourceId (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:83:44)
    at /Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:55:47
    at DiagramComponent.subTreeFindComponentRec (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/component/component.js:137:13)
    at DiagramComponent.subTreeFindComponent (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/component/component.js:134:21)
    at /Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/component/component.js:140:23
    at Array.map (<anonymous>)
    at DiagramComponent.subTreeFindComponentRec (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/component/component.js:139:40)
    at DiagramComponent.subTreeFindComponent (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/component/component.js:134:21)
    at AwsEdgeResolver.findTargetComponent (/Users/stickb/Code/bayer/seed-sight/node_modules/.pnpm/cdk-dia@0.10.0_@aws-cdk+cloud-assembly-schema@1.203.0_@aws-cdk+cx-api@1.203.0_@aws-cdk+region_mfjzhpc43jo4i3uy5j2k3imhm4/node_modules/cdk-dia/dist/src/diagram/aws/aws-edge-resolver.js:54:47)

Node.js v18.15.0

Strangely, this succeeds: pnpm cdk-dia --include ss-pipeline/ss-dev/data ss-pipeline/ss-dev/waf ss-pipeline/ss-dev/ui ss-pipeline/ss-dev/analysis cross-region-stack-349310182770:us-east-1 which should be the same as the previous command, right?