Skip to content

Commit 9afd03b

Browse files
authored
Trap some error instances for DB (#1746)
* Also add a copy of dev DB in both clean state and dirty state. No user/pass included ... currently leave that up to end collaboration since handled via environment variable. Applies to #1745 #37 Refs: * `mongorestore --gzip --db openuserjs_devel --archive=./dev/devDBdirty.gz` * `mongodump --gzip --db openuserjs_devel --archive=./dev/devDBclean.gz` * `CONNECT_STRING=mongodb://127.0.0.1:27017/openuserjs_devel` Auto-merge
1 parent 6c1036b commit 9afd03b

File tree

5 files changed

+25
-4
lines changed

5 files changed

+25
-4
lines changed

.gitignore

+2
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@ lib-cov
77
*.out
88
*.pid
99
*.gz
10+
!dev/devDBclean.gz
11+
!dev/devDBdirty.gz
1012

1113
pids
1214
logs

app.js

+7-2
Original file line numberDiff line numberDiff line change
@@ -103,8 +103,13 @@ app.set('securePort', process.env.SECURE_PORT || null);
103103
mongoose.connect(connectStr, dbOptions);
104104

105105
// Trap a few events for MongoDB
106-
db.on('error', function () {
107-
console.error(colors.red('MongoDB connection error'));
106+
db.on('error', function (aErr) {
107+
console.error( colors.red( [
108+
'MongoDB connection error',
109+
aErr.message,
110+
'Terminating app'
111+
].join('\n')));
112+
process.exit(1); // NOTE: Watchpoint
108113
});
109114

110115
db.once('open', function () {

dev/devDBclean.gz

667 Bytes
Binary file not shown.

dev/devDBdirty.gz

135 KB
Binary file not shown.

libs/repoManager.js

+16-2
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ var statusError = require('../libs/debug').statusError;
88

99
//--- Dependency inclusions
1010
var util = require('util');
11-
11+
var colors = require('ansi-colors');
1212

1313
//--- Model inclusions
1414
var Sync = require('../models/sync').Sync;
@@ -32,7 +32,21 @@ var clientId = null;
3232
var clientKey = null;
3333

3434
Strategy.findOne({ name: 'github' }, function (aErr, aStrat) {
35-
// WARNING: No err handling
35+
if (aErr) {
36+
console.error( aErr.message );
37+
process.exit(1);
38+
return;
39+
}
40+
41+
if (!aStrat) {
42+
console.error( colors.red( [
43+
'Default GitHub Strategy document not found in DB',
44+
'Terminating app'
45+
].join('\n')));
46+
47+
process.exit(1);
48+
return;
49+
}
3650

3751
clientId = aStrat.id;
3852
clientKey = aStrat.key;

0 commit comments

Comments
 (0)