Skip to content

Commit

Permalink
Merge pull request FlowiseAI#1786 from Jaredude/bug/nodespool-file-ma…
Browse files Browse the repository at this point in the history
…p-error-handling

handles scenario where NodesPool require call fails
  • Loading branch information
HenryHengZJ authored Feb 24, 2024
2 parents 6247b67 + 23f7e78 commit 2290ba9
Show file tree
Hide file tree
Showing 2 changed files with 30 additions and 24 deletions.
51 changes: 28 additions & 23 deletions packages/server/src/NodesPool.ts
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ import { Dirent } from 'fs'
import { getNodeModulesPackagePath } from './utils'
import { promises } from 'fs'
import { ICommonObject } from 'flowise-components'
import logger from './utils/logger'

export class NodesPool {
componentNodes: IComponentNodes = {}
Expand All @@ -28,36 +29,40 @@ export class NodesPool {
return Promise.all(
nodeFiles.map(async (file) => {
if (file.endsWith('.js')) {
const nodeModule = await require(file)
try {
const nodeModule = await require(file)

if (nodeModule.nodeClass) {
const newNodeInstance = new nodeModule.nodeClass()
newNodeInstance.filePath = file
if (nodeModule.nodeClass) {
const newNodeInstance = new nodeModule.nodeClass()
newNodeInstance.filePath = file

// Replace file icon with absolute path
if (
newNodeInstance.icon &&
(newNodeInstance.icon.endsWith('.svg') ||
newNodeInstance.icon.endsWith('.png') ||
newNodeInstance.icon.endsWith('.jpg'))
) {
const filePath = file.replace(/\\/g, '/').split('/')
filePath.pop()
const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}`
newNodeInstance.icon = nodeIconAbsolutePath
// Replace file icon with absolute path
if (
newNodeInstance.icon &&
(newNodeInstance.icon.endsWith('.svg') ||
newNodeInstance.icon.endsWith('.png') ||
newNodeInstance.icon.endsWith('.jpg'))
) {
const filePath = file.replace(/\\/g, '/').split('/')
filePath.pop()
const nodeIconAbsolutePath = `${filePath.join('/')}/${newNodeInstance.icon}`
newNodeInstance.icon = nodeIconAbsolutePath

// Store icon path for componentCredentials
if (newNodeInstance.credential) {
for (const credName of newNodeInstance.credential.credentialNames) {
this.credentialIconPath[credName] = nodeIconAbsolutePath
// Store icon path for componentCredentials
if (newNodeInstance.credential) {
for (const credName of newNodeInstance.credential.credentialNames) {
this.credentialIconPath[credName] = nodeIconAbsolutePath
}
}
}
}

const skipCategories = ['Analytic']
if (!skipCategories.includes(newNodeInstance.category)) {
this.componentNodes[newNodeInstance.name] = newNodeInstance
const skipCategories = ['Analytic']
if (!skipCategories.includes(newNodeInstance.category)) {
this.componentNodes[newNodeInstance.name] = newNodeInstance
}
}
} catch (err) {
logger.error(`❌ [server]: Error during initDatabase with file ${file}:`, err)
}
}
})
Expand Down
3 changes: 2 additions & 1 deletion packages/server/src/index.ts
Original file line number Diff line number Diff line change
Expand Up @@ -85,7 +85,7 @@ export class App {
// Initialize database
this.AppDataSource.initialize()
.then(async () => {
logger.info('📦 [server]: Data Source has been initialized!')
logger.info('📦 [server]: Data Source is being initialized!')

// Run Migrations Scripts
await this.AppDataSource.runMigrations({ transaction: 'each' })
Expand All @@ -112,6 +112,7 @@ export class App {

// Initialize telemetry
this.telemetry = new Telemetry()
logger.info('📦 [server]: Data Source has been initialized!')
})
.catch((err) => {
logger.error('❌ [server]: Error during Data Source initialization:', err)
Expand Down

0 comments on commit 2290ba9

Please sign in to comment.