Skip to content

Commit

Permalink
Make ActivityObject TypeErrors more descriptive
Browse files Browse the repository at this point in the history
This should help us fix #801.
  • Loading branch information
strugee committed Jul 15, 2017
1 parent 49237b8 commit 9c83b9f
Showing 1 changed file with 11 additions and 11 deletions.
22 changes: 11 additions & 11 deletions lib/model/activityobject.js
Original file line number Diff line number Diff line change
Expand Up @@ -517,7 +517,7 @@ ActivityObject.ensureProperty = function(obj, name, callback) {
}

if (!_.isObject(obj[name])) {
callback(new TypeError(name + " property of " + obj + " is not an object"));
callback(new TypeError(name + " property of " + obj + " is a " + typeof obj[name] + ", not an object"));
return;
}

Expand Down Expand Up @@ -1078,13 +1078,13 @@ ActivityObject.validate = function(props) {
// XXX: validate that displayName is not HTML

if (_.has(props, "displayName") && !_.isString(props.displayName)) {
throw new TypeError("displayName property is not a string");
throw new TypeError("displayName property is a " + typeof props.displayName + ", not a string");
}

// XXX: validate that url is an URL

if (_.has(props, "url") && !_.isString(props.url)) {
throw new TypeError("url property is not a string");
throw new TypeError("url property is a " + typeof props.url + ", not a string");
}

_.each(oprops, function(name) {
Expand All @@ -1101,11 +1101,11 @@ ActivityObject.validate = function(props) {

if (_.has(props, "attachments")) {
if (!_.isArray(props.attachments)) {
throw new TypeError("attachments is not an array");
throw new TypeError("attachments is a " + typeof props.attachments + ", not an array");
}
_.each(props.attachments, function(attachment) {
if (!_.isObject(attachment)) {
throw new TypeError("attachment is not an object");
throw new TypeError("attachment is a " + typeof attachment + ", not an object");
}
ActivityObject.validate(attachment);
});
Expand All @@ -1114,7 +1114,7 @@ ActivityObject.validate = function(props) {
_.each(uriarrayprops, function(uriarrayprop) {
if (_.has(props, uriarrayprop)) {
if (!_.isArray(props[uriarrayprop])) {
throw new TypeError(uriarrayprop + " is not an array");
throw new TypeError(uriarrayprop + " is a " + typeof props[uriarrayprop] + ", not an array");
}

if (_.some(props[uriarrayprop], function(str) { return !_.isString(str); })) {
Expand All @@ -1127,7 +1127,7 @@ ActivityObject.validate = function(props) {

if (_.has(props, "image")) {
if (!_.isObject(props.image)) {
throw new TypeError("image property is not an object");
throw new TypeError("image property is a " + typeof props.image + ", not an object");
}

ActivityObject.validateMediaLink(props.image);
Expand All @@ -1138,15 +1138,15 @@ ActivityObject.validate = function(props) {

if (_.has(props, dateprop)) {
if (!_.isString(props[dateprop])) {
throw new TypeError(dateprop + " property is not a string");
throw new TypeError(dateprop + " property is a " + typeof props[dateprop] + ", not a string");
}
}
});

_.each(htmlprops, function(name) {
// XXX: validate HTML
if (_.has(props, name) && !_.isString(props[name])) {
throw new TypeError(name + " property is not a string");
throw new TypeError(name + " property is a " + typeof props[name] + ", not a string");
}
});

Expand All @@ -1158,12 +1158,12 @@ ActivityObject.validateMediaLink = function(props) {
var np = ["width", "height", "duration"];

if (!_.isString(props.url)) {
throw new TypeError("url property of media link is not a string");
throw new TypeError("url property of media link is a " + typeof props.url + ", not a string");
}

_.each(np, function(nprop) {
if (_.has(props, nprop) && !_.isNumber(props[nprop])) {
throw new TypeError(nprop + " property of media link is not a number");
throw new TypeError(nprop + " property of media link is a " + typeof props[nprop] + ", not a number");
}
});

Expand Down

0 comments on commit 9c83b9f

Please sign in to comment.