-
Notifications
You must be signed in to change notification settings - Fork 19.4k
Description
Self Checks
- I have read the Contributing Guide and Language Policy.
- This is only for bug report, if you would like to ask a question, please head to Discussions.
- I have searched for existing issues search for existing issues, including closed ones.
- I confirm that I am using English to submit this report, otherwise it will be closed.
- 【中文用户 & Non English User】请使用英语提交,否则会被关闭 :)
- Please do not modify this template :) and fill in all the required fields.
Dify version
1.10.1
Cloud or Self Hosted
Cloud
Steps to reproduce
When running Workflow nodes, the browser console displays a TypeError that crashes the application and prevents proper workflow execution.
Error Details
Error Message:
TypeError: Cannot set properties of undefined (setting 'type')
Stack Trace:
78536-0e29f6099381af25.js:75 Uncaught TypeError: Cannot set properties of undefined (setting 'type')
at 78536-0e29f6099381af25.js:75:51800
at push.8894.U.constructor.produce (51246-404ebadb6c77138b.js:5:17938)
at 78536-0e29f6099381af25.js:75:51784
at 78536-0e29f6099381af25.js:75:49953
at i8 (2de95d4b-8278ff6b72f9ce97.js:1:135370)
at 2de95d4b-8278ff6b72f9ce97.js:1:141456
at nz (2de95d4b-8278ff6b72f9ce97.js:1:19204)
at sn (2de95d4b-8278ff6b72f9ce97.js:1:136603)
at cc (2de95d4b-8278ff6b72f9ce97.js:1:163605)
at ci (2de95d4b-8278ff6b72f9ce97.js:1:163427)
Root Cause Analysis
Issue Location: web/service/base.ts file, handleStream function
Problem: When processing Server-Sent Events (SSE) streams, if the received JSON data is malformed or truncated, JSON parsing fails and bufferObj is set to undefined. However, subsequent code attempts to access properties of bufferObj without checking for null/undefined values first.
Code Context:
try {
bufferObj = JSON.parse(message.substring(6)) as Record<string, any>
} catch {
// mute handle message cut off
bufferObj = undefined
onData?('', isFirstMessage, {
conversationId: undefined,
messageId: '',
})
return
}
// Later code without null check:
bufferObj.event // This can cause the errorSteps to Reproduce
- Create a new Workflow in Dify
- Add any node type (e.g., LLM, Code node, etc.)
- Run the workflow node
- Observe browser console errors
Environment Information
- Component: Web frontend
- Files Affected:
web/service/base.ts - Function:
handleStream - Error Context: Server-Sent Events (SSE) stream processing
- Browser: Any modern browser (Chrome, Firefox, Safari, Edge)
Impact
- Workflow execution fails with JavaScript errors
- Poor user experience with unclear error messages
- Potential data loss or incomplete processing
- Application stability issues
Proposed Fix
Add null/undefined check for bufferObj before accessing its properties:
if (!bufferObj) {
onData('', false, {
conversationId: undefined,
messageId: '',
errorMessage: 'Invalid response data',
errorCode: 'invalid_data',
})
hasError = true
onCompleted?.(true, 'Invalid response data')
return
}This ensures graceful error handling when encountering malformed JSON data in the SSE stream, preventing the TypeError and providing proper error feedback.
Priority
Severity: Medium
Impact: Workflow functionality
Complexity: Low (simple null check)
✔️ Expected Behavior
The workflow should execute successfully without any JavaScript errors in the browser console. When processing Server-Sent Events (SSE) streams, the application should:
- Handle well-formed JSON data normally and display workflow results
- Gracefully handle malformed or truncated JSON data with proper error messages
- Provide clear feedback to users about any issues that occur during execution
- Maintain application stability and prevent crashes
- Allow users to understand what went wrong through meaningful error messages
❌ Actual Behavior
When running workflow nodes, the application encounters a TypeError that crashes the execution:
- JavaScript Error:
Cannot set properties of undefined (setting 'type')appears in browser console - Workflow Failure: The workflow execution stops immediately and no results are displayed
- Poor Error Handling: The error provides no meaningful feedback to users about what went wrong
- Application Instability: The error may affect other parts of the application or subsequent workflow runs
- Data Loss Risk: Incomplete processing may result in lost data or partial results