Loopback-datasource-juggler: Fail when connector is missing

Created on 9 Oct 2014  路  4Comments  路  Source: loopbackio/loopback-datasource-juggler

Shouldn't the entire thing fail completely instead of just a warning if a connector is missing?

// Currently (my version of code) it just outputs a warning and drives on.
if (!connector) {
    error = util.format('\nWARNING: LoopBack connector "%s" is not installed ' +
      'as any of the following modules:\n\n %s\n\nTo fix, run:\n\n    npm install %s\n',
      name, names.join('\n'), names[names.length -1]);
  }

Most helpful comment

I think even the error msg starting with Warning but it eventually throws error and crashes the app if connector module not found.
See:

WARNING: LoopBack connector "db2" is not installed as any of the following modules:

 ./connectors/db2
loopback-connector-db2

To fix, run:

    npm install loopback-connector-db2

/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:243
    throw err;
    ^

Error: Cannot create data source "mydb2": 
WARNING: LoopBack connector "db2" is not installed as any of the following modules:

 ./connectors/db2
loopback-connector-db2

To fix, run:

    npm install loopback-connector-db2

    at DataSource.setup (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-datasource-juggler/lib/datasource.js:308:28)
    at new DataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-datasource-juggler/lib/datasource.js:114:8)
    at Registry.createDataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/registry.js:354:12)
    at dataSourcesFromConfig (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:435:19)
    at EventEmitter.app.dataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:233:14)
    at /Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:188:9
    at /Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:279:5
    at Array.forEach (native)
    at forEachKeyedObject (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:278:20)
    at setupDataSources (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:178:3)

I am closing it since the error is handled properly to force user installing a connector.

Feel free to reopen it if I am wrong :)

All 4 comments

@raymondfeng @ritch what's your opinion? Do you remember the reason why there is a warning only? The app will fail on the first operation that calls a method that should have been provided by the missing connector.

I personally prefer to fail fast at the point where the problem was detected, instead of crashing the app later with "undefined is not a function".

The behavior was inherited from jugglingdb. I'm open to fail fast. The only use case I can think of is to allow loading the app inside the studio with some error tolerance. For example, we want to test the connection to mysql even if the oracle one is not working.

Maybe one option is to push non-fatal errors into a stack during the boot process and allow the post boot code to decide.

I think even the error msg starting with Warning but it eventually throws error and crashes the app if connector module not found.
See:

WARNING: LoopBack connector "db2" is not installed as any of the following modules:

 ./connectors/db2
loopback-connector-db2

To fix, run:

    npm install loopback-connector-db2

/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:243
    throw err;
    ^

Error: Cannot create data source "mydb2": 
WARNING: LoopBack connector "db2" is not installed as any of the following modules:

 ./connectors/db2
loopback-connector-db2

To fix, run:

    npm install loopback-connector-db2

    at DataSource.setup (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-datasource-juggler/lib/datasource.js:308:28)
    at new DataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-datasource-juggler/lib/datasource.js:114:8)
    at Registry.createDataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/registry.js:354:12)
    at dataSourcesFromConfig (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:435:19)
    at EventEmitter.app.dataSource (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback/lib/application.js:233:14)
    at /Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:188:9
    at /Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:279:5
    at Array.forEach (native)
    at forEachKeyedObject (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:278:20)
    at setupDataSources (/Users/jannyhou/lb/triage/lb693/loopback-sandbox/node_modules/loopback-boot/lib/executor.js:178:3)

I am closing it since the error is handled properly to force user installing a connector.

Feel free to reopen it if I am wrong :)

merci 莽a marche

Was this page helpful?
0 / 5 - 0 ratings