Skip to content

fix(layout.DirectedGraph): better error message when dagre fails to connect to container #2838

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 9 commits into
base: master
Choose a base branch
from

Conversation

zbynekstara
Copy link
Contributor

@zbynekstara zbynekstara commented Dec 18, 2024

Description

Provides a better error message when dagre fails due to trying to connect a child to a container.

See #455 for more information and workarounds.

@zbynekstara zbynekstara force-pushed the directed-graph-type-error branch from ee6df96 to 8204e21 Compare January 14, 2025 14:47
Copy link

This PR is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label Mar 16, 2025
@kumilingus kumilingus removed the stale This issue/PR shows no activity for an extended period of time. label Mar 17, 2025
Copy link

This PR is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label May 17, 2025
@zbynekstara zbynekstara removed the stale This issue/PR shows no activity for an extended period of time. label May 20, 2025
@zbynekstara zbynekstara force-pushed the directed-graph-type-error branch from 8204e21 to 7f0eb64 Compare May 20, 2025 07:49
@zbynekstara zbynekstara requested a review from Copilot May 20, 2025 07:55
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

Adds a new validation step to DirectedGraph.layout to catch invalid links between container and child elements and introduces tests for both validation-enabled and disabled modes.

  • Introduces a validateGraph method that throws a clear error when linking a child to its container.
  • Adds a validateGraph option to the layout API (default true) and wires it into layout.
  • Adds QUnit tests covering scenarios where validation is on or off.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/joint-layout-directed-graph/test/index.js New QUnit test for container–child connection errors
packages/joint-layout-directed-graph/DirectedGraph.mjs Added validateGraph method and integrated its use
Comments suppressed due to low confidence (1)

packages/joint-layout-directed-graph/DirectedGraph.mjs:123

  • [nitpick] Enhance this error message with contextual information (e.g. source and target element IDs) to make debugging easier, for example: DirectedGraph: cannot connect child ${source.id} to container ${target.id}.
throw new Error('DirectedGraph: It is not possible to connect a child to a container.');

@zbynekstara zbynekstara requested a review from Copilot May 20, 2025 09:34
Copy link

@Copilot Copilot AI left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull Request Overview

This PR adds pre-layout validation to DirectedGraph to catch invalid parent/child connections earlier and provides clearer error messaging when such cases occur.

  • Introduces validateGraph to detect links between containers and children before invoking Dagre.
  • Updates layout to call validateGraph based on the validateGraph option.
  • Adds new tests in test/index.js to verify the custom error message and fallback behavior when validation is disabled.

Reviewed Changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 3 comments.

File Description
packages/joint-layout-directed-graph/test/index.js New QUnit tests covering invalid container/child links and error messages
packages/joint-layout-directed-graph/DirectedGraph.mjs Added validateGraph method and hooked it into layout
Comments suppressed due to low confidence (1)

packages/joint-layout-directed-graph/DirectedGraph.mjs:126

  • [nitpick] The error message only mentions "child to a container" but this validator also catches "container to child" and "container to container" cases. Consider updating the message (or making it parametric) to accurately reflect all invalid connection types.
throw new Error('DirectedGraph: It is not possible to connect a child to a container.');

Copy link

This PR is stale because it has been open 60 days with no activity. Please remove stale label or comment or this will be closed in 14 days.

@github-actions github-actions bot added the stale This issue/PR shows no activity for an extended period of time. label Jul 20, 2025
@github-actions github-actions bot closed this Aug 3, 2025
@zbynekstara zbynekstara reopened this Aug 4, 2025
@zbynekstara zbynekstara removed the stale This issue/PR shows no activity for an extended period of time. label Aug 4, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants