Skip to content

Commit

Permalink
Enhance error handling when dealing with probable Lindt nodes
Browse files Browse the repository at this point in the history
  • Loading branch information
Rosuav committed Dec 30, 2024
1 parent 4749467 commit 0855484
Show file tree
Hide file tree
Showing 3 changed files with 10 additions and 2 deletions.
7 changes: 6 additions & 1 deletion factory.js
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,11 @@ function append_child(elem, child) {
}
if (typeof child === "string" || typeof child === "number") child = document.createTextNode(child);
if (child instanceof Node) elem.appendChild(child);
else if (child.tag && child.attributes && Array.isArray(child.children))
//It looks like a Lindt template. We can't just bounce to replace_content though as we might be
//inside an array; otherwise, this check could be done in set_content and the two get unified.
throw new Error("Attempted to insert non-Node object into document - did you mean replace_content?",
{cause: {elem, child}});
else throw new Error("Attempted to insert non-Node object into document",
{cause: {elem, child}});
}
Expand Down Expand Up @@ -379,7 +384,7 @@ function autobind(obj, prop) {
choc = new Proxy(choc, {get: autobind});
lindt = new Proxy(lindt, {get: autobind});

choc.__version__ = "1.9.2";
choc.__version__ = "1.9.3";

//For modules, make the main entry-point easily available.
export default choc;
Expand Down
2 changes: 1 addition & 1 deletion package.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "chocfactory",
"version": "1.9.2",
"version": "1.9.3",
"description": "Simple JS front end library",
"main": "factory.js",
"scripts": {
Expand Down
3 changes: 3 additions & 0 deletions whatsnew.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,8 @@
## Chocolate Factory version history

### v1.9.3
* Augment the "non-Node object" error if it looks like a Lindt template

### v1.9.2
* Detect children inside arrays (out of context, that sounds nice and weird)

Expand Down

0 comments on commit 0855484

Please sign in to comment.