code: function getErrorMessage (err, target, defaultMsg) {
      var errMessage;
      if (err) {
          errMessage = err.toString();
      } else {
          errMessage = defaultMsg;
      }
      return errMessage.replace('%target%', target);
  }
docs: err might be null, in which case defaultMsg is used. target MUST be defined or an error is thrown.