Skip to content

fix(editor): Show an error when imported JSON is not a valid workflow#31782

Merged
CharlieKolb merged 3 commits into
n8n-io:masterfrom
hammadxcm:fix-import-invalid-workflow-feedback
Jun 9, 2026
Merged

fix(editor): Show an error when imported JSON is not a valid workflow#31782
CharlieKolb merged 3 commits into
n8n-io:masterfrom
hammadxcm:fix-import-invalid-workflow-feedback

Conversation

@hammadxcm

Copy link
Copy Markdown
Contributor

Summary

Importing a workflow file (or URL/pasted JSON) that is syntactically valid JSON but not a workflow — i.e. it has no nodes/connections properties — silently resulted in an empty canvas with no feedback.

importWorkflowData in useCanvasOperations short-circuited with return {} when the data didn't look like a workflow, without notifying the user:

// If it is JSON check if it looks on the first look like data we can use
if (!workflowData.hasOwnProperty('nodes') || !workflowData.hasOwnProperty('connections')) {
	return {};
}

This PR shows the existing "Problem importing workflow" error toast with a new message — "The imported data does not contain valid workflow data ('nodes' and 'connections' are missing)" — before returning, matching the established convention of the invalid-nodes toast directly below this check.

How to test

  1. Create a JSON file with valid syntax that is not a workflow, e.g. { "name": "hello" }.
  2. In the editor, use the workflow menu → Import from File and select it.
    • Before: nothing happens (empty canvas, no message).
    • After: an error toast "Problem importing workflow — The imported data does not contain valid workflow data ('nodes' and 'connections' are missing)" is shown.

Unit tests cover both the invalid-shape path (toast shown, nothing imported) and the valid path (no toast).

Related Linear tickets, Github issues, and Community forum posts

Fixes #31646

Review / Merge checklist

  • I have seen this code, I have run this code, and I take responsibility for this code.
  • PR title and summary are descriptive.
  • Tests included.

Importing a file (or URL/pasted JSON) that is syntactically valid JSON
but does not contain workflow data silently resulted in an empty canvas.
importWorkflowData short-circuited with an empty return when 'nodes' or
'connections' were missing, without notifying the user.

Show the existing 'Problem importing workflow' error toast with a new
message before returning, matching the invalid-nodes toast convention
used directly below this check.

@cubic-dev-ai cubic-dev-ai Bot left a comment

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.

No issues found across 3 files

Architecture diagram
sequenceDiagram
    participant User as User
    participant Editor as Editor UI
    participant CanvasOp as useCanvasOperations
    participant I18n as i18n Service
    participant Toast as Toast Service

    User->>Editor: Import workflow (file / URL / paste)
    Editor->>CanvasOp: importWorkflowData(rawData, source)
    Note over CanvasOp: JSON already parsed here (existing)
    CanvasOp->>CanvasOp: Check hasOwnProperty('nodes') and hasOwnProperty('connections')
    alt Missing 'nodes' or 'connections'
        Note over CanvasOp: NEW: invalid structure detected
        CanvasOp->>I18n: baseText('invalidStructure')
        I18n-->>CanvasOp: localized message
        CanvasOp->>I18n: baseText('importError.title')
        I18n-->>CanvasOp: "Problem importing workflow"
        CanvasOp->>Toast: showError(Error(msg), title)
        Note over Toast: Error toast displayed
        CanvasOp-->>Editor: return {} (empty)
        Editor-->>User: Canvas unchanged, no workflow imported
    else Valid workflow structure
        Note over CanvasOp: Continue with existing import logic
        CanvasOp->>CanvasOp: Import nodes, connections, etc.
        CanvasOp-->>Editor: Workflow data
        Editor->>Editor: Update canvas
        Editor-->>User: Workflow displayed
    end
Loading

Re-trigger cubic

@n8n-assistant n8n-assistant Bot added community Authored by a community member in linear DEPRECATED labels Jun 4, 2026
@n8n-assistant

n8n-assistant Bot commented Jun 4, 2026

Copy link
Copy Markdown
Contributor

Hey @hammadxcm,

Thank you for your contribution. We appreciate the time and effort you’ve taken to submit this pull request.

Before we can proceed, please ensure the following:
• Tests are included for any new functionality, logic changes or bug fixes.
• The PR aligns with our contribution guidelines.

Regarding new nodes:
We no longer accept new nodes directly into the core codebase. Instead, we encourage contributors to follow our Community Node Submission Guide to publish nodes independently.

If your node integrates with an AI service that you own or represent, please email nodes@n8n.io and we will be happy to discuss the best approach.

About review timelines:
This PR has been added to our internal tracker as "GHC-8628". While we plan to review it, we are currently unable to provide an exact timeframe. Our goal is to begin reviews within a month, but this may change depending on team priorities. We will reach out when the review begins.

Thank you again for contributing to n8n.

@Joffcom Joffcom added team:adore Issue is with the Adore team status:team-assigned A team has been assigned the issue or PR triage:complete Triage has been completed and issue is ready for internal teams labels Jun 8, 2026
@codecov

codecov Bot commented Jun 9, 2026

Copy link
Copy Markdown

Codecov Report

✅ All modified and coverable lines are covered by tests.

📢 Thoughts on this report? Let us know!

@CharlieKolb CharlieKolb left a comment

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.

Nice! 🚀

@CharlieKolb CharlieKolb added this pull request to the merge queue Jun 9, 2026
@github-merge-queue github-merge-queue Bot removed this pull request from the merge queue due to failed status checks Jun 9, 2026
@CharlieKolb CharlieKolb added this pull request to the merge queue Jun 9, 2026
Merged via the queue into n8n-io:master with commit 0731871 Jun 9, 2026
122 of 127 checks passed
@n8n-assistant n8n-assistant Bot mentioned this pull request Jun 16, 2026
@n8n-assistant

n8n-assistant Bot commented Jun 17, 2026

Copy link
Copy Markdown
Contributor

Got released with n8n@

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

cla-signed community Authored by a community member in linear DEPRECATED status:team-assigned A team has been assigned the issue or PR team:adore Issue is with the Adore team triage:complete Triage has been completed and issue is ready for internal teams

Projects

None yet

Development

Successfully merging this pull request may close these issues.

import of invalid json fails silently

3 participants