fix(editor): Show an error when imported JSON is not a valid workflow#31782
Conversation
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.
There was a problem hiding this comment.
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
|
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: Regarding new nodes: 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: Thank you again for contributing to n8n. |
Codecov Report✅ All modified and coverable lines are covered by tests. 📢 Thoughts on this report? Let us know! |
|
Got released with |
Summary
Importing a workflow file (or URL/pasted JSON) that is syntactically valid JSON but not a workflow — i.e. it has no
nodes/connectionsproperties — silently resulted in an empty canvas with no feedback.importWorkflowDatainuseCanvasOperationsshort-circuited withreturn {}when the data didn't look like a workflow, without notifying the user: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
{ "name": "hello" }.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