 getEffectiveUser = (user, callback) ->
   # Find all users with user.shortName in their canBeReally list
   User.findCanBeReally user.shortName, (err, canBeReally) ->
+    if err?
+      return callback err, null
     if user.defaultContext in _.pluck(canBeReally, 'shortName')
       # User has a defaultContext, and it is one of the contexts they can switch to.
       effectiveUser = _.findWhere canBeReally, shortName: user.defaultContext
     else
       effectiveUser = user
-    return callback effectiveUser
+    return callback null, effectiveUser
 
 # Verify callback for LocalStrategy
 verify = (username, password, callback) ->

      # User logged in successfully!
      # Now we need to work out which 'effective'
      # profile they should be logged into...
      getEffectiveUser user, (effectiveUser) ->
        sessionUser =
          real: getSessionUser user
          effective: getSessionUser effectiveUser

    if err?
      console.warn err
      return resp.send 500, error: 'Error trying to find datasets'

    return resp.send 200, datasets

getDataset = (req, resp) ->
