Skip to content

fix: Improve flow export error handling and validation#8943

Merged
carlosrcoelho merged 4 commits into
mainfrom
cz/fix-download-api-flow
Jul 9, 2025
Merged

fix: Improve flow export error handling and validation#8943
carlosrcoelho merged 4 commits into
mainfrom
cz/fix-download-api-flow

Conversation

@Cristhianzl
Copy link
Copy Markdown
Member

@Cristhianzl Cristhianzl commented Jul 8, 2025

This pull request improves the flow export functionality in the ExportModal component by adding error handling and ensuring the downloadFlow function returns a value. It also updates the downloadFlow utility function to return a promise, enabling better control over the flow export process.

Changes to ExportModal component:

  • Updated the onSubmit method in src/frontend/src/modals/exportModal/index.tsx to handle errors during the export process and check if the downloadFlow function returns a valid file path before proceeding with success or warning notices. [1] [2] [3]

Changes to downloadFlow utility function:

  • Modified the downloadFlow function in src/frontend/src/utils/reactflowUtils.ts to return a Promise of string | undefined | void, allowing the caller to determine the success of the operation.
  • Ensured the customDownloadFlow invocation within downloadFlow returns a value and added error propagation for better error handling.

Summary by CodeRabbit

  • Bug Fixes

    • Improved export modal to handle errors during export, providing clearer feedback if a download fails.
    • Ensured export operation is completed before closing the modal or displaying alerts.
  • New Features

    • Added success and error notifications for export actions, enhancing user feedback during downloads.

… export functionality and error handling

♻️ (reactflowUtils.ts): Refactor downloadFlow function to return a Promise and improve error handling
@Cristhianzl Cristhianzl self-assigned this Jul 8, 2025
@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jul 8, 2025

Important

Review skipped

Auto incremental reviews are disabled on this repository.

Please check the settings in the CodeRabbit UI or the .coderabbit.yaml file in this repository. To trigger a single review, invoke the @coderabbitai review command.

You can disable this status message by setting the reviews.review_status to false in the CodeRabbit configuration file.

Walkthrough

The export modal's submission logic was refactored to handle asynchronous export operations with proper error handling. The downloadFlow utility function was updated to return a Promise and propagate errors, ensuring that the export modal can accurately respond to success or failure scenarios during flow export.

Changes

File(s) Change Summary
src/frontend/src/modals/exportModal/index.tsx Refactored export modal's onSubmit handler to be async, await export, handle errors, and set alerts.
src/frontend/src/utils/reactflowUtils.ts Updated downloadFlow to return a Promise, await internal calls, and rethrow errors after logging.

Sequence Diagram(s)

sequenceDiagram
    participant User
    participant ExportModal
    participant reactflowUtils
    participant customDownloadFlow

    User->>ExportModal: Submit export form
    ExportModal->>reactflowUtils: await downloadFlow(flow, name, description)
    reactflowUtils->>customDownloadFlow: await customDownloadFlow(...)
    customDownloadFlow-->>reactflowUtils: filePath or error
    reactflowUtils-->>ExportModal: filePath or error
    alt Success
        ExportModal->>ExportModal: Set success/notice alert, close modal, track event
    else Error
        ExportModal->>Console: Log error
    end
Loading

Possibly related PRs

Suggested labels

size:S, lgtm

Suggested reviewers

  • Cristhianzl
  • lucaseduoli
  • mfortman11
✨ Finishing Touches
🧪 Generate unit tests
  • Create PR with unit tests
  • Post copyable unit tests in a comment
  • Commit unit tests in branch cz/fix-download-api-flow

Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out.

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Explain this complex logic.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai explain this code block.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and explain its main purpose.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Support

Need help? Create a ticket on our support page for assistance with any issues or questions.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR.
  • @coderabbitai generate sequence diagram to generate a sequence diagram of the changes in this PR.
  • @coderabbitai auto-generate unit tests to generate unit tests for this PR.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@dosubot dosubot Bot added the size:M This PR changes 30-99 lines, ignoring generated files. label Jul 8, 2025
…error in export flow to improve code readability
@dosubot dosubot Bot added the bug Something isn't working label Jul 8, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 8, 2025
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 2

📜 Review details

Configuration used: .coderabbit.yaml
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 24db0cd and 4c69ecc.

📒 Files selected for processing (2)
  • src/frontend/src/modals/exportModal/index.tsx (1 hunks)
  • src/frontend/src/utils/reactflowUtils.ts (2 hunks)
🧰 Additional context used
📓 Path-based instructions (2)
`src/frontend/**/*.{ts,tsx}`: Use React 18 with TypeScript for all UI components and frontend logic.

src/frontend/**/*.{ts,tsx}: Use React 18 with TypeScript for all UI components and frontend logic.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)

List of files the instruction was applied to:

  • src/frontend/src/modals/exportModal/index.tsx
  • src/frontend/src/utils/reactflowUtils.ts
`src/frontend/**/*.{ts,tsx,js,jsx,css,scss}`: Use Tailwind CSS for styling all frontend components.

src/frontend/**/*.{ts,tsx,js,jsx,css,scss}: Use Tailwind CSS for styling all frontend components.

📄 Source: CodeRabbit Inference Engine (.cursor/rules/frontend_development.mdc)

List of files the instruction was applied to:

  • src/frontend/src/modals/exportModal/index.tsx
  • src/frontend/src/utils/reactflowUtils.ts
🧠 Learnings (3)
📓 Common learnings
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/components/**/*FlowGraph.tsx : Use React Flow for flow graph visualization components.
src/frontend/src/modals/exportModal/index.tsx (3)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/{hooks,services}/**/*.{ts,tsx} : All API calls must implement proper error handling, typically using try/catch and setting error state.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/components/**/*FlowGraph.tsx : Use React Flow for flow graph visualization components.
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-23T12:46:42.048Z
Learning: Custom React Flow node types should be implemented as memoized components, using Handle components for connection points and supporting optional icons and labels.
src/frontend/src/utils/reactflowUtils.ts (1)
Learnt from: CR
PR: langflow-ai/langflow#0
File: .cursor/rules/frontend_development.mdc:0-0
Timestamp: 2025-06-30T14:40:29.510Z
Learning: Applies to src/frontend/src/components/**/*FlowGraph.tsx : Use React Flow for flow graph visualization components.
🧬 Code Graph Analysis (1)
src/frontend/src/modals/exportModal/index.tsx (3)
src/frontend/src/utils/reactflowUtils.ts (2)
  • downloadFlow (1903-1927)
  • removeApiKeys (472-483)
src/frontend/src/constants/alerts_constants.tsx (1)
  • API_WARNING_NOTICE_ALERT (49-50)
src/frontend/src/customization/utils/analytics.ts (1)
  • track (1-7)
🪛 Biome (1.9.4)
src/frontend/src/modals/exportModal/index.tsx

[error] 58-58: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

src/frontend/src/utils/reactflowUtils.ts

[error] 1907-1908: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🔇 Additional comments (3)
src/frontend/src/utils/reactflowUtils.ts (1)

1922-1926: Excellent error handling improvements.

The changes to await the customDownloadFlow call and rethrow errors instead of swallowing them significantly improve error propagation and debugging capabilities. This aligns well with the PR objectives of improving error handling.

src/frontend/src/modals/exportModal/index.tsx (2)

56-110: Excellent async refactoring with proper error handling.

The conversion from synchronous to asynchronous handling is well-implemented:

  • Proper try/catch error handling
  • Conditional logic correctly handles both export scenarios (with/without API keys)
  • Success validation using the returned filePath
  • Appropriate user feedback through alerts
  • Consistent tracking and modal closure on success

This aligns perfectly with the PR objectives of improving flow export error handling and validation.


60-82: Verify consistent behavior between export modes.

The conditional logic properly handles both export scenarios, but ensure that the success/failure validation logic is consistent between the two branches. Both branches correctly:

  • Await the downloadFlow call
  • Check for truthy filePath return value
  • Show appropriate alerts and close modal on success
  • Track the export event

flowName: string,
flowDescription?: string,
) {
): Promise<string | undefined | void> {
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix confusing void type in union type.

The void type is confusing in union types and should be replaced with undefined for clarity.

Apply this diff to fix the type issue:

-): Promise<string | undefined | void> {
+): Promise<string | undefined> {
📝 Committable suggestion

‼️ IMPORTANT
Carefully review the code before committing. Ensure that it accurately replaces the highlighted code, contains no missing lines, and has no issues with indentation. Thoroughly test & benchmark the code to ensure it meets the requirements.

Suggested change
): Promise<string | undefined | void> {
): Promise<string | undefined> {
🧰 Tools
🪛 Biome (1.9.4)

[error] 1907-1908: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🤖 Prompt for AI Agents
In src/frontend/src/utils/reactflowUtils.ts at line 1907, the return type
includes a union with void, which is confusing. Replace the void type in the
union with undefined to clarify the return type, so it becomes Promise<string |
undefined> instead of Promise<string | undefined | void>.

data: currentFlow!.data!,
onSubmit={async () => {
try {
let filePath: string | undefined | void;
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

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

⚠️ Potential issue

Fix confusing void type in union type.

The void type is confusing in union types and should be replaced with undefined for clarity, consistent with the downloadFlow function signature.

Apply this diff to fix the type issue:

-          let filePath: string | undefined | void;
+          let filePath: string | undefined;
🧰 Tools
🪛 Biome (1.9.4)

[error] 58-58: void is confusing inside a union type.

Unsafe fix: Use undefined instead.

(lint/suspicious/noConfusingVoidType)

🤖 Prompt for AI Agents
In src/frontend/src/modals/exportModal/index.tsx at line 58, the variable
filePath is declared with a union type including void, which is confusing.
Change the type annotation to only include string and undefined, removing void,
to match the downloadFlow function signature and improve clarity.

Copy link
Copy Markdown
Collaborator

@lucaseduoli lucaseduoli left a comment

Choose a reason for hiding this comment

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

LGTM

@dosubot dosubot Bot added the lgtm This PR has been approved by a maintainer label Jul 8, 2025
@github-actions
Copy link
Copy Markdown
Contributor

github-actions Bot commented Jul 8, 2025

Frontend Unit Test Coverage Report

Coverage Summary

Lines Statements Branches Functions
Coverage: 71%
73.58% (117/159) 57.46% (77/134) 59.52% (25/42)

Unit Test Results

Tests Skipped Failures Errors Time
45 0 💤 0 ❌ 0 🔥 2.569s ⏱️

@carlosrcoelho carlosrcoelho enabled auto-merge July 8, 2025 23:12
…implify logic for exporting flows

💡 (exportModal/index.tsx): refactor code to improve readability and remove redundant code for exporting flows
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 9, 2025
@github-actions github-actions Bot added bug Something isn't working and removed bug Something isn't working labels Jul 9, 2025
@carlosrcoelho carlosrcoelho added this pull request to the merge queue Jul 9, 2025
Merged via the queue into main with commit eb69cdd Jul 9, 2025
63 of 64 checks passed
@carlosrcoelho carlosrcoelho deleted the cz/fix-download-api-flow branch July 9, 2025 13:07
smatiolids pushed a commit to smatiolids/langflow-dev that referenced this pull request Jul 10, 2025
)

* ✨ (exportModal/index.tsx): Refactor onSubmit function to improve flow export functionality and error handling
♻️ (reactflowUtils.ts): Refactor downloadFlow function to return a Promise and improve error handling

* 📝 (exportModal/index.tsx): remove unnecessary comment about handling error in export flow to improve code readability

* 🐛 (exportModal/index.tsx): remove unnecessary filePath variable and simplify logic for exporting flows
💡 (exportModal/index.tsx): refactor code to improve readability and remove redundant code for exporting flows
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

bug Something isn't working lgtm This PR has been approved by a maintainer size:M This PR changes 30-99 lines, ignoring generated files.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants