Build Agentic workflows, RAG pipelines, with rich AI model and tool support on one collaborative workspace. Deploy on cloud, VPC, or self-hosted, so teams move from prototype to production without rebuilding the stack.
Python agentagentic-aiagentic-frameworkagentic-workflowaiautomationclaudedeepseekgenaigptllmlow-codemcpnextjsno-codeopenaipythonskillsworkflow
fix: prevent client-side crashes from null/undefined plugin data in workflow (#23154) (#23182)
lyzno11b2046da3f6d
diff --git a/web/__tests__/check-i18n.test.ts b/web/__tests__/check-i18n.test.tsindex 173aa961189..3bde095f4b5 100644--- a/web/__tests__/check-i18n.test.ts+++ b/web/__tests__/check-i18n.test.ts@@ -49,9 +49,9 @@ describe('check-i18n script functionality', () => {}vm.runInNewContext(transpile(content), context)- const translationObj = moduleExports.default || moduleExports+ const translationObj = (context.module.exports as any).default || context.module.exports- if(!translationObj || typeof translationObj !== 'object')+ if (!translationObj || typeof translationObj !== 'object')throw new Error(`Error parsing file: ${filePath}`)const nestedKeys: string[] = []@@ -62,7 +62,7 @@ describe('check-i18n script functionality', () => {// This is an object (but not array), recurse into it but don't add it as a keyiterateKeys(obj[key], nestedKey)}- else {+ else {// This is a leaf node (string, number, boolean, array, etc.), add it as a keynestedKeys.push(nestedKey)}@@ -73,7 +73,7 @@ describe('check-i18n script functionality', () => {const fileKeys = nestedKeys.map(key => `${camelCaseFileName}.${key}`)allKeys.push(...fileKeys)}- catch (error) {+ catch (error) {reject(error)}})@@ -272,9 +272,6 @@ export default translationconst filteredEnKeys = allEnKeys.filter(key =>key.startsWith(targetFile.replace(/[-_](.)/g, (_, c) => c.toUpperCase())),)- const filteredZhKeys = allZhKeys.filter(key =>- key.startsWith(targetFile.replace(/[-_](.)/g, (_, c) => c.toUpperCase())),- )expect(allEnKeys).toHaveLength(4) // 2 keys from each fileexpect(filteredEnKeys).toHaveLength(2) // only components keysdiff --git a/web/__tests__/plugin-tool-workflow-error.test.tsx b/web/__tests__/plugin-tool-workflow-error.test.tsxnew file mode 100644index 00000000000..370052bc80d--- /dev/null+++ b/web/__tests__/plugin-tool-workflow-error.test.tsx@@ -0,0 +1,207 @@+/**+ * Test cases to reproduce the plugin tool workflow error+ * Issue: #23154 - Application error when loading plugin tools in workflow+ * Root cause: split() operation called on null/undefined values+ */++describe('Plugin Tool Workflow Error Reproduction', () => {+ /**+ * Mock function to simulate the problematic code in switch-plugin-version.tsx:29+ * const [pluginId] = uniqueIdentifier.split(':')+ */+ const mockSwitchPluginVersionLogic = (uniqueIdentifier: string | null | undefined) => {+ // This directly reproduces the problematic line from switch-plugin-version.tsx:29+ const [pluginId] = uniqueIdentifier!.split(':')+ return pluginId+ }++ /**+ * Test case 1: Simulate null uniqueIdentifier+ * This should reproduce the error mentioned in the issue+ */+ it('should reproduce error when uniqueIdentifier is null', () => {+ expect(() => {+ mockSwitchPluginVersionLogic(null)+ }).toThrow('Cannot read properties of null (reading \'split\')')+ })++ /**+ * Test case 2: Simulate undefined uniqueIdentifier+ */+ it('should reproduce error when uniqueIdentifier is undefined', () => {+ expect(() => {+ mockSwitchPluginVersionLogic(undefined)+ }).toThrow('Cannot read properties of undefined (reading \'split\')')+ })++ /**+ * Test case 3: Simulate empty string uniqueIdentifier+ */+ it('should handle empty string uniqueIdentifier', () => {+ expect(() => {+ const result = mockSwitchPluginVersionLogic('')+ expect(result).toBe('') // Empty string split by ':' returns ['']+ }).not.toThrow()+ })++ /**+ * Test case 4: Simulate malformed uniqueIdentifier without colon separator+ */+ it('should handle malformed uniqueIdentifier without colon separator', () => {+ expect(() => {+ const result = mockSwitchPluginVersionLogic('malformed-identifier-without-colon')+ expect(result).toBe('malformed-identifier-without-colon') // No colon means full string returned+ }).not.toThrow()+ })++ /**+ * Test case 5: Simulate valid uniqueIdentifier+ */+ it('should work correctly with valid uniqueIdentifier', () => {+ expect(() => {+ const result = mockSwitchPluginVersionLogic('valid-plugin-id:1.0.0')+ expect(result).toBe('valid-plugin-id')+ }).not.toThrow()+ })+})++/**+ * Test for the variable processing split error in use-single-run-form-params+ */+describe('Variable Processing Split Error', () => {+ /**+ * Mock function to simulate the problematic code in use-single-run-form-params.ts:91+ * const getDependentVars = () => {+ * return varInputs.map(item => item.variable.slice(1, -1).split('.'))+ * }+ */+ const mockGetDependentVars = (varInputs: Array<{ variable: string | null | undefined }>) => {+ return varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0) // Filter out empty arrays+ }++ /**+ * Test case 1: Variable processing with null variable+ */+ it('should handle null variable safely', () => {+ const varInputs = [{ variable: null }]++ expect(() => {+ mockGetDependentVars(varInputs)+ }).not.toThrow()++ const result = mockGetDependentVars(varInputs)+ expect(result).toEqual([]) // null variables are filtered out+ })++ /**+ * Test case 2: Variable processing with undefined variable+ */+ it('should handle undefined variable safely', () => {+ const varInputs = [{ variable: undefined }]++ expect(() => {+ mockGetDependentVars(varInputs)+ }).not.toThrow()++ const result = mockGetDependentVars(varInputs)+ expect(result).toEqual([]) // undefined variables are filtered out+ })++ /**+ * Test case 3: Variable processing with empty string+ */+ it('should handle empty string variable', () => {+ const varInputs = [{ variable: '' }]++ expect(() => {+ mockGetDependentVars(varInputs)+ }).not.toThrow()++ const result = mockGetDependentVars(varInputs)+ expect(result).toEqual([]) // Empty string is filtered out, so result is empty array+ })++ /**+ * Test case 4: Variable processing with valid variable format+ */+ it('should work correctly with valid variable format', () => {+ const varInputs = [{ variable: '{{workflow.node.output}}' }]++ expect(() => {+ mockGetDependentVars(varInputs)+ }).not.toThrow()++ const result = mockGetDependentVars(varInputs)+ expect(result[0]).toEqual(['{workflow', 'node', 'output}'])+ })+})++/**+ * Integration test to simulate the complete workflow scenario+ */+describe('Plugin Tool Workflow Integration', () => {+ /**+ * Simulate the scenario where plugin metadata is incomplete or corrupted+ * This can happen when:+ * 1. Plugin is being loaded from marketplace but metadata request fails+ * 2. Plugin configuration is corrupted in database+ * 3. Network issues during plugin loading+ */+ it('should reproduce the client-side exception scenario', () => {+ // Mock incomplete plugin data that could cause the error+ const incompletePluginData = {+ // Missing or null uniqueIdentifier+ uniqueIdentifier: null,+ meta: null,+ minimum_dify_version: undefined,+ }++ // This simulates the error path that leads to the white screen+ expect(() => {+ // Simulate the code path in switch-plugin-version.tsx:29+ // The actual problematic code doesn't use optional chaining+ const _pluginId = (incompletePluginData.uniqueIdentifier as any).split(':')[0]+ }).toThrow('Cannot read properties of null (reading \'split\')')+ })++ /**+ * Test the scenario mentioned in the issue where plugin tools are loaded in workflow+ */+ it('should simulate plugin tool loading in workflow context', () => {+ // Mock the workflow context where plugin tools are being loaded+ const workflowPluginTools = [+ {+ provider_name: 'test-plugin',+ uniqueIdentifier: null, // This is the problematic case+ tool_name: 'test-tool',+ },+ {+ provider_name: 'valid-plugin',+ uniqueIdentifier: 'valid-plugin:1.0.0',+ tool_name: 'valid-tool',+ },+ ]++ // Process each plugin tool+ workflowPluginTools.forEach((tool, _index) => {+ if (tool.uniqueIdentifier === null) {+ // This reproduces the exact error scenario+ expect(() => {+ const _pluginId = (tool.uniqueIdentifier as any).split(':')[0]+ }).toThrow()+ }+ else {+ // Valid tools should work fine+ expect(() => {+ const _pluginId = tool.uniqueIdentifier.split(':')[0]+ }).not.toThrow()+ }+ })+ })+})diff --git a/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx b/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsxindex 94b3ce7bfc2..7ecbbd5602e 100644--- a/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx+++ b/web/app/components/workflow/nodes/_base/components/switch-plugin-version.tsx@@ -26,7 +26,8 @@ export type SwitchPluginVersionProps = {export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {const { uniqueIdentifier, tooltip, onChange, className } = props- const [pluginId] = uniqueIdentifier.split(':')++ const [pluginId] = uniqueIdentifier?.split(':') || ['']const [isShow, setIsShow] = useState(false)const [isShowUpdateModal, { setTrue: showUpdateModal, setFalse: hideUpdateModal }] = useBoolean(false)const [target, setTarget] = useState<{@@ -60,6 +61,11 @@ export const SwitchPluginVersion: FC<SwitchPluginVersionProps> = (props) => {})}const { t } = useTranslation()++ // Guard against null/undefined uniqueIdentifier to prevent app crash+ if (!uniqueIdentifier || !pluginId)+ return null+return <Tooltip popupContent={!isShow && !isShowUpdateModal && tooltip} triggerMethod='hover'><div className={cn('flex w-fit items-center justify-center', className)} onClick={e => e.stopPropagation()}>{isShowUpdateModal && pluginDetail && <PluginMutationModeldiff --git a/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts b/web/app/components/workflow/nodes/agent/use-single-run-form-params.tsindex 5ddc24b2f20..09f329b94d5 100644--- a/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/agent/use-single-run-form-params.ts@@ -77,7 +77,13 @@ const useSingleRunFormParams = ({}, [runResult, t])const getDependentVars = () => {- return varInputs.map(item => item.variable.slice(1, -1).split('.'))+ return varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)}return {diff --git a/web/app/components/workflow/nodes/http/use-single-run-form-params.ts b/web/app/components/workflow/nodes/http/use-single-run-form-params.tsindex c5d65634c47..42f39c4d32b 100644--- a/web/app/components/workflow/nodes/http/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/http/use-single-run-form-params.ts@@ -62,7 +62,13 @@ const useSingleRunFormParams = ({}, [inputVarValues, setInputVarValues, varInputs])const getDependentVars = () => {- return varInputs.map(item => item.variable.slice(1, -1).split('.'))+ return varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)}return {diff --git a/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts b/web/app/components/workflow/nodes/llm/use-single-run-form-params.tsindex 93a8638d05b..2480bbee315 100644--- a/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/llm/use-single-run-form-params.ts@@ -168,7 +168,13 @@ const useSingleRunFormParams = ({})()const getDependentVars = () => {- const promptVars = varInputs.map(item => item.variable.slice(1, -1).split('.'))+ const promptVars = varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)const contextVar = payload.context.variable_selectorconst vars = [...promptVars, contextVar]if (isVisionModel && payload.vision?.enabled && payload.vision?.configs?.variable_selector) {diff --git a/web/app/components/workflow/nodes/parameter-extractor/use-single-run-form-params.ts b/web/app/components/workflow/nodes/parameter-extractor/use-single-run-form-params.tsindex 178f9e3ed81..f920ff1555f 100644--- a/web/app/components/workflow/nodes/parameter-extractor/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/parameter-extractor/use-single-run-form-params.ts@@ -120,7 +120,13 @@ const useSingleRunFormParams = ({})()const getDependentVars = () => {- const promptVars = varInputs.map(item => item.variable.slice(1, -1).split('.'))+ const promptVars = varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)const vars = [payload.query, ...promptVars]if (isVisionModel && payload.vision?.enabled && payload.vision?.configs?.variable_selector) {const visionVar = payload.vision.configs.variable_selectordiff --git a/web/app/components/workflow/nodes/question-classifier/use-single-run-form-params.ts b/web/app/components/workflow/nodes/question-classifier/use-single-run-form-params.tsindex 66755abb6ed..9bbb3e1d5d9 100644--- a/web/app/components/workflow/nodes/question-classifier/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/question-classifier/use-single-run-form-params.ts@@ -118,7 +118,13 @@ const useSingleRunFormParams = ({})()const getDependentVars = () => {- const promptVars = varInputs.map(item => item.variable.slice(1, -1).split('.'))+ const promptVars = varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)const vars = [payload.query_variable_selector, ...promptVars]if (isVisionModel && payload.vision?.enabled && payload.vision?.configs?.variable_selector) {const visionVar = payload.vision.configs.variable_selectordiff --git a/web/app/components/workflow/nodes/tool/use-single-run-form-params.ts b/web/app/components/workflow/nodes/tool/use-single-run-form-params.tsindex 6fc79beebe3..13b1da6b01a 100644--- a/web/app/components/workflow/nodes/tool/use-single-run-form-params.ts+++ b/web/app/components/workflow/nodes/tool/use-single-run-form-params.ts@@ -88,7 +88,13 @@ const useSingleRunFormParams = ({const toolIcon = useToolIcon(payload)const getDependentVars = () => {- return varInputs.map(item => item.variable.slice(1, -1).split('.'))+ return varInputs.map((item) => {+ // Guard against null/undefined variable to prevent app crash+ if (!item.variable || typeof item.variable !== 'string')+ return []++ return item.variable.slice(1, -1).split('.')+ }).filter(arr => arr.length > 0)}return {