Skip to content

Commit 291f1f5

Browse files
fix(log): prevent error when no transports exist (#1306)
1 parent 7000a5b commit 291f1f5

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

lib/commands/log.js

+1-1
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ class LogCommand extends Command {
3131
// TODO: fallback to process manager log retrieval?
3232
return Promise.reject(new errors.ConfigError({
3333
config: {
34-
'logging.transports': instance.config.get('logging.transports').join(', ')
34+
'logging.transports': instance.config.get('logging.transports', []).join(', ')
3535
},
3636
message: 'You have excluded file logging in your ghost config. ' +
3737
'You need to add it to your transport config to use this command.',

test/unit/commands/log-spec.js

+16
Original file line numberDiff line numberDiff line change
@@ -132,6 +132,22 @@ describe('Unit: Commands > Log', function () {
132132
});
133133
});
134134

135+
it('Rejects without crashing when logging to file is disabled', function () {
136+
const ext = proxyLog();
137+
const instance = {
138+
isRunning: () => Promise.resolve(true),
139+
config: {get: (key, fallback) => fallback}
140+
};
141+
ext.system = {getInstance: () => instance};
142+
143+
return ext.run({name: 'ghost_org'}).then(() => {
144+
expect(false, 'An error should have been thrown').to.be.true;
145+
}).catch((error) => {
146+
expect(error).to.be.ok;
147+
expect(error).to.be.instanceOf(Errors.ConfigError);
148+
});
149+
});
150+
135151
it('Reads error log when requested', function () {
136152
stubs.es.throws(new Error('SHORT_CIRCUIT'));
137153
const ext = proxyLog({fs: {existsSync: stubs.es}});

0 commit comments

Comments
 (0)