Skip to content
This repository has been archived by the owner on Apr 17, 2023. It is now read-only.

Return error on getStats if Redis client is undefined #33

Merged

Conversation

aidenkeating
Copy link
Contributor

@aidenkeating aidenkeating commented Aug 16, 2017

Currently when calling getStats, if the first sync call has not been
made yet, an error will be thrown stating it cannot get lrange of undefined.

This is a messy error and doesn't explain what is actually going on.

This adds an error message explaining that the client is not
initialised and that an initial sync is required.

Currently when calling getStats, if the first sync call has not been
made yet, an 'cannot get value of undefined' error will be thrown.

This adds an error message explaining that the client is not
initialised and that an initial sync is required.
@aidenkeating aidenkeating force-pushed the error-if-undefined-redis-client branch from f365e57 to 8c9d0bc Compare August 16, 2017 10:30
@aidenkeating
Copy link
Contributor Author

aidenkeating commented Aug 16, 2017

@david-martin @wtrocki Would you mind taking a look?

Edit: The changes here are mostly indentation. These are the actual lines: L151, L174-177

@wtrocki wtrocki self-requested a review August 16, 2017 10:43
if (err) {
debugError('Failed to get values from redis for key %s with error : %s', metricName, err);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

We going to miss that debug in new version. (not sure if that was intentional and we debug callback bellow.
Gong to check that.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'll add a debugError statement on L175 to ensure this is logged.

That debug would be if the redis client itself had an error, the current change checks if the redis client actually exists. So we'll still hit it when relevant.

@wtrocki
Copy link
Member

wtrocki commented Aug 16, 2017

@aidenkeating - Awesome contribution. This change may also partially resolve this issue:
#25

Can you provide verification steps to avoid misunderstandings?

@aidenkeating
Copy link
Contributor Author

@wtrocki Verification can be done using this PR. feedhenry/fh-sync-server#5

  • Pull down the fh-sync-server PR and install dependencies
  • npm link this fh-sync branch into fh-sync-server
  • Run the server - node app.js
  • curl localhost:3000/sys/info/stats and ensure the error message is returned
  • Ensure fh-sync-server performs a sync, this can be done using the demo app in fh-sync-js
  • curl localhost:3000/sys/info/stats and ensure stats are returned

async.map(metricsToFetch, function(metric, callback) {
var metricName = metric.metricName;
redisClient.lrange([statsNamespace, metricName].join(':'), 0, MAX_NUMBER, function(err, data) {
if (redisClient) {
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this change will work, but I think the code will be cleaner if we do it this way:

var getStats = function(cb) {
  if(! redisClient) {
    return cb(new Error(....));
  }
  //the rest of code that need no changes
}

WDYT?

@wtrocki
Copy link
Member

wtrocki commented Aug 16, 2017

Verified!

Aiden Keating added 2 commits August 16, 2017 15:25
@aidenkeating aidenkeating force-pushed the error-if-undefined-redis-client branch from a5afe89 to 69fdec6 Compare August 16, 2017 14:25
@aidenkeating
Copy link
Contributor Author

Thanks for review/verification, addressed comments, merging

@aidenkeating aidenkeating merged commit 69fdec6 into feedhenry:master Aug 16, 2017
@aidenkeating
Copy link
Contributor Author

Published as fh-sync@1.0.10 (https://www.npmjs.com/package/fh-sync)

@aidenkeating aidenkeating deleted the error-if-undefined-redis-client branch August 16, 2017 14:34
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants