mirror of
https://github.com/serverless/serverless.git
synced 2026-01-25 15:07:39 +00:00
Merge pull request #2313 from horike37/issue-1604
Add Catch Errors for Tracking
This commit is contained in:
commit
03b94b8563
@ -38,17 +38,22 @@ class SlStats {
|
||||
const statsDisabledFilePath = path.join(serverlessDirPath, 'stats-disabled');
|
||||
const statsEnabledFilePath = path.join(serverlessDirPath, 'stats-enabled');
|
||||
|
||||
if (this.options.enable && !this.options.disable) {
|
||||
if (this.serverless.utils.fileExistsSync(statsDisabledFilePath)) {
|
||||
fse.renameSync(statsDisabledFilePath, statsEnabledFilePath);
|
||||
try {
|
||||
if (this.options.enable && !this.options.disable) {
|
||||
if (fse.lstatSync(statsDisabledFilePath).isFile()) {
|
||||
fse.renameSync(statsDisabledFilePath, statsEnabledFilePath);
|
||||
}
|
||||
this.serverless.cli.log('Stats successfully enabled');
|
||||
}
|
||||
this.serverless.cli.log('Stats successfully enabled');
|
||||
}
|
||||
if (this.options.disable && !this.options.enable) {
|
||||
if (this.serverless.utils.fileExistsSync(statsEnabledFilePath)) {
|
||||
fse.renameSync(statsEnabledFilePath, statsDisabledFilePath);
|
||||
if (this.options.disable && !this.options.enable) {
|
||||
if (fse.lstatSync(statsEnabledFilePath).isFile()) {
|
||||
fse.renameSync(statsEnabledFilePath, statsDisabledFilePath);
|
||||
}
|
||||
this.serverless.cli.log('Stats successfully disabled');
|
||||
}
|
||||
this.serverless.cli.log('Stats successfully disabled');
|
||||
} catch (error) {
|
||||
throw new this.serverless.classes
|
||||
.Error(`Enabling / Disabling of statistics failed: ${error.message}`);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@ -82,6 +82,19 @@ describe('SlStats', () => {
|
||||
).to.equal(false);
|
||||
});
|
||||
|
||||
it('should throw an error if the stats file does not exist', () => {
|
||||
slStats.options = { enable: true };
|
||||
|
||||
expect(() => slStats.toggleStats()).to.throw(Error,
|
||||
/Enabling \/ Disabling of statistics failed: ENOENT: no such file or directory, lstat/);
|
||||
expect(
|
||||
serverless.utils.fileExistsSync(path.join(serverlessDirPath, 'stats-enabled'))
|
||||
).to.equal(false);
|
||||
expect(
|
||||
serverless.utils.fileExistsSync(path.join(serverlessDirPath, 'stats-disabled'))
|
||||
).to.equal(false);
|
||||
});
|
||||
|
||||
afterEach(() => {
|
||||
// recover the homeDir
|
||||
process.env.HOME = homeDir;
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user