Skip to content

Commit

Permalink
fix(log): prevent error when no transports exist (#1306)
Browse files Browse the repository at this point in the history
  • Loading branch information
vikaspotluri123 authored Oct 3, 2020
1 parent 7000a5b commit 291f1f5
Show file tree
Hide file tree
Showing 2 changed files with 17 additions and 1 deletion.
2 changes: 1 addition & 1 deletion lib/commands/log.js
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,7 @@ class LogCommand extends Command {
// TODO: fallback to process manager log retrieval?
return Promise.reject(new errors.ConfigError({
config: {
'logging.transports': instance.config.get('logging.transports').join(', ')
'logging.transports': instance.config.get('logging.transports', []).join(', ')
},
message: 'You have excluded file logging in your ghost config. ' +
'You need to add it to your transport config to use this command.',
Expand Down
16 changes: 16 additions & 0 deletions test/unit/commands/log-spec.js
Original file line number Diff line number Diff line change
Expand Up @@ -132,6 +132,22 @@ describe('Unit: Commands > Log', function () {
});
});

it('Rejects without crashing when logging to file is disabled', function () {
const ext = proxyLog();
const instance = {
isRunning: () => Promise.resolve(true),
config: {get: (key, fallback) => fallback}
};
ext.system = {getInstance: () => instance};

return ext.run({name: 'ghost_org'}).then(() => {
expect(false, 'An error should have been thrown').to.be.true;
}).catch((error) => {
expect(error).to.be.ok;
expect(error).to.be.instanceOf(Errors.ConfigError);
});
});

it('Reads error log when requested', function () {
stubs.es.throws(new Error('SHORT_CIRCUIT'));
const ext = proxyLog({fs: {existsSync: stubs.es}});
Expand Down

0 comments on commit 291f1f5

Please sign in to comment.