Skip to content

Commit

Permalink
format object error string
Browse files Browse the repository at this point in the history
  • Loading branch information
Matt-Esch committed Dec 27, 2014
1 parent 8788f80 commit ec82016
Showing 1 changed file with 14 additions and 2 deletions.
16 changes: 14 additions & 2 deletions virtual-hyperscript/index.js
Original file line number Diff line number Diff line change
Expand Up @@ -113,11 +113,23 @@ function UnexpectedVirtualElement(data) {
err.type = 'virtual-hyperscript.unexpected.virtual-element';
err.message = 'Unexpected virtual child passed to h().\n' +
'Expected a VNode / Vthunk / VWidget / string but:\n' +
'got a {foreignObjectStr}.\n' +
'The parent vnode is {parentVnodeStr}.\n' +
'got:\n' +
errorString(data.foreignObject) +
'.\n' +
'The parent vnode is:\n' +
errorString(data.parentVnode)
'\n' +
'Suggested fix: change your `h(..., [ ... ])` callsite.';
err.foreignObject = data.foreignObject;
err.parentVnode = data.parentVnode;

return err;
}

function errorString(obj) {
try {
return JSON.stringify(obj, null, ' ');
} catch (e) {
return String(obj);
}
}

0 comments on commit ec82016

Please sign in to comment.