Skip to content

Commit b299ad5

Browse files
authored
Merge pull request #83 from jherdman/better-error-message-for-redis-urls
Better Error Message for Bad Redis URLs
2 parents 3edcc48 + 7884291 commit b299ad5

File tree

2 files changed

+31
-0
lines changed

2 files changed

+31
-0
lines changed

index.js

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -74,6 +74,12 @@ module.exports = {
7474

7575
if (!this.pluginConfig.url) {
7676
['host', 'port'].forEach(this.applyDefaultConfigProperty.bind(this));
77+
} else {
78+
var redisUrlRegexp = new RegExp('^redis://');
79+
80+
if (!this.pluginConfig.url.match(redisUrlRegexp)) {
81+
throw new Error('Your Redis URL appears to be missing the "redis://" protocol. Update your URL to: redis://' + this.pluginConfig.url);
82+
}
7783
}
7884

7985
['filePattern', 'distDir', 'keyPrefix', 'activationSuffix', 'activeContentSuffix', 'revisionKey', 'didDeployMessage', 'redisDeployClient', 'maxRecentUploads', 'revisionData'].forEach(this.applyDefaultConfigProperty.bind(this));

tests/unit/index-test.js

Lines changed: 25 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,31 @@ describe('redis plugin', function() {
143143

144144
assert.equal(redisLib.createdClient.options, 'redis://:password@host.amazonaws.com:6379/4');
145145
});
146+
147+
it('throws if the Redis URL is missing the "redis://" protocol', function() {
148+
var plugin = subject.createDeployPlugin({
149+
name: 'redis'
150+
});
151+
152+
var redisLib = new FakeRedis();
153+
154+
var context = {
155+
ui: mockUi,
156+
project: stubProject,
157+
config: {
158+
redis: {
159+
url: 'host.amazonaws.com:6379/4'
160+
}
161+
},
162+
_redisLib: redisLib
163+
};
164+
165+
plugin.beforeHook(context);
166+
167+
assert.throws(function() {
168+
plugin.configure(context);
169+
}, 'Your Redis URL appears to be missing the "redis://" protocol. Update your URL to: redis://host.amazonaws.com:6379/4');
170+
});
146171
});
147172

148173
describe('resolving port from the pipeline', function() {

0 commit comments

Comments
 (0)