Skip to content

Commit d51a462

Browse files
committed
Minor optimizations to the error handling #17
1 parent 23b7b95 commit d51a462

File tree

5 files changed

+21
-40
lines changed

5 files changed

+21
-40
lines changed

definitions/errors.js

Lines changed: 0 additions & 30 deletions
This file was deleted.

definitions/index.js

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,9 +1,7 @@
11
const constants = require('./constants');
2-
const errors = require('./errors');
32

43
module.exports = class definitions {
54
constructor() {
65
this.constants = constants;
7-
this.errors = errors;
86
}
97
};

preprocessor/errors.js

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
exports.PreProcessError = class PreProcessError extends Error {
2+
constructor(...args) {
3+
super(...args);
4+
this.code = 'ERR_PREPROCESS';
5+
this.name = 'PreProcessError';
6+
this.stack = `${this.message}\n${new Error().stack}`;
7+
}
8+
};

preprocessor/index.js

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@ const path = require('path');
44
const { promisify } = require('util');
55
const cson = require('cson');
66
const { checksum } = require('./utils');
7+
const { PreProcessError } = require('./errors');
78

89
const readFile = promisify(fs.readFile);
910
const getStat = promisify(fs.stat);
@@ -13,9 +14,8 @@ class PreProcessor {
1314
this.container = container;
1415
this.logger = logger;
1516
this.platform = process.platform;
16-
const { constants, errors } = this.container.module('definitions');
17+
const { constants } = this.container.module('definitions');
1718
this.constants = constants;
18-
this.errors = errors;
1919
}
2020

2121
async processChangeSet(event, changedFile) {
@@ -65,10 +65,13 @@ class PreProcessor {
6565
};
6666
} catch (err) {
6767
// if err.code === 'ENOENT', it means that the 'changedFile' has been removed
68-
return {
69-
event: this.constants.events.FILE_DELETE,
70-
file: changedFile
71-
};
68+
if (err.code === 'ENOENT') {
69+
return {
70+
event: this.constants.events.FILE_DELETE,
71+
file: changedFile
72+
};
73+
}
74+
throw new PreProcessError(`Error occurred while preprocessing event: ${err.message}`);
7275
}
7376
}
7477
}

sync/index.js

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,9 +21,8 @@ module.exports = class Sync {
2121
this.lock = new Lock();
2222
this.preprocessor = this.container.module('preprocessor');
2323
this.github = this.container.module('github');
24-
const { constants, errors } = this.container.module('definitions');
24+
const { constants } = this.container.module('definitions');
2525
this.constants = constants;
26-
this.errors = errors;
2726
}
2827

2928
/**
@@ -65,6 +64,9 @@ module.exports = class Sync {
6564
this.queue.enqueue(syncEvent);
6665
this.logger.info(`[Queue] ${this.queue.length()} items in sync queue!`);
6766
this.triggerSync();
67+
})
68+
.catch((err) => {
69+
this.logger.error('Preprocess failed', err);
6870
});
6971
}
7072

0 commit comments

Comments
 (0)