Skip to content

Commit 9037a50

Browse files
committed
refactor: enhance error handling in document store interactions
1 parent 873273d commit 9037a50

File tree

4 files changed

+14
-12
lines changed

4 files changed

+14
-12
lines changed

packages/components/nodes/agentflow/Agent/Agent.ts

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,7 @@ import { Tool } from '@langchain/core/tools'
1919
import { ARTIFACTS_PREFIX, SOURCE_DOCUMENTS_PREFIX, TOOL_ARGS_PREFIX } from '../../../src/agents'
2020
import { flatten } from 'lodash'
2121
import zodToJsonSchema from 'zod-to-json-schema'
22-
import { getErrorMessage } from '../../../src/error'
22+
import { DocumentStoreError, getErrorMessage } from '../../../src/error'
2323
import { DataSource } from 'typeorm'
2424
import {
2525
getPastChatHistoryImageMessages,
@@ -28,7 +28,6 @@ import {
2828
replaceBase64ImagesWithFileReferences,
2929
updateFlowState
3030
} from '../utils'
31-
import { DocumentStoreError } from '../../../src/error'
3231

3332
interface ITool {
3433
agentSelectedTool: string
@@ -610,7 +609,10 @@ class Agent_Agentflow implements INode {
610609
})
611610
} catch (error) {
612611
if (error instanceof DocumentStoreError) {
613-
console.warn(`Failed to initialize document store ${knowledgeBase.documentStore}, skipping:`, error.message)
612+
console.warn(
613+
`Failed to initialize document store ${knowledgeBase.documentStore}, skipping:`,
614+
getErrorMessage(error)
615+
)
614616
continue
615617
}
616618
throw error

packages/components/nodes/tools/RetrieverTool/RetrieverTool.ts

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ import { getBaseClasses, resolveFlowObjValue } from '../../../src/utils'
77
import { SOURCE_DOCUMENTS_PREFIX } from '../../../src/agents'
88
import { RunnableConfig } from '@langchain/core/runnables'
99
import { VectorStoreRetriever } from '@langchain/core/vectorstores'
10+
import { getErrorMessage } from '../../../src/error'
1011

1112
const howToUse = `Add additional filters to vector store. You can also filter with flow config, including the current "state":
1213
- \`$flow.sessionId\`
@@ -209,13 +210,12 @@ class Retriever_Tools implements INode {
209210
const sourceDocuments = JSON.stringify(docs)
210211
return returnSourceDocuments ? content + SOURCE_DOCUMENTS_PREFIX + sourceDocuments : content
211212
} catch (error) {
213+
const errorMessage = getErrorMessage(error)
212214
const isDocStoreError =
213-
error.message &&
214-
(error.message.includes('document store') ||
215-
error.message.includes('vector store') ||
216-
error.message.includes('retriever'))
215+
errorMessage &&
216+
(errorMessage.includes('document store') || errorMessage.includes('vector store') || errorMessage.includes('retriever'))
217217
if (isDocStoreError) {
218-
console.warn('Document store retrieval failed, returning fallback response:', error.message)
218+
console.warn('Document store retrieval failed, returning fallback response:', getErrorMessage(error))
219219
return 'Knowledge base temporarily unavailable. Proceeding with general knowledge.'
220220
}
221221
throw error

packages/components/nodes/vectorstores/DocumentStoreVS/DocStoreVector.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
import { ICommonObject, IDatabaseEntity, INode, INodeData, INodeOptionsValue, INodeOutputsValue, INodeParams } from '../../../src/Interface'
22
import { DataSource } from 'typeorm'
3-
import { DocumentStoreError } from '../../../src/error'
3+
import { DocumentStoreError, getErrorMessage } from '../../../src/error'
44

55
class DocStore_VectorStores implements INode {
66
label: string
@@ -118,7 +118,7 @@ class DocStore_VectorStores implements INode {
118118
if (error instanceof DocumentStoreError) {
119119
throw error
120120
}
121-
throw new DocumentStoreError(error.message, nodeData.inputs?.selectedStore)
121+
throw new DocumentStoreError(getErrorMessage(error), nodeData.inputs?.selectedStore)
122122
}
123123
}
124124
}

packages/server/src/utils/buildAgentflow.ts

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1229,7 +1229,7 @@ const executeNode = async ({
12291229
getErrorMessage(error).includes('Knowledge base temporarily unavailable')
12301230

12311231
if (isDocStoreError && !isAborted) {
1232-
console.warn(`Document store error in node ${nodeId}, continuing execution:`, getErrorMessage(error))
1232+
logger.warn(`Document store error in node ${nodeId}, continuing execution:`, getErrorMessage(error))
12331233
agentFlowExecutedData.push({
12341234
nodeId,
12351235
nodeLabel: reactFlowNode.data.label,
@@ -1802,7 +1802,7 @@ export const executeAgentFlow = async ({
18021802
getErrorMessage(error).includes('Knowledge base temporarily unavailable')
18031803
// Handle document store errors more gracefully
18041804
if (isDocStoreError && !isAborted) {
1805-
console.warn(`Document store error in node ${currentNode.nodeId}, continuing execution:`, getErrorMessage(error))
1805+
logger.warn(`Document store error in node ${currentNode.nodeId}, continuing execution:`, getErrorMessage(error))
18061806
// Add warning to execution data instead of error
18071807
agentFlowExecutedData.push({
18081808
nodeId: currentNode.nodeId,

0 commit comments

Comments
 (0)