Skip to content

Commit 54bdfc1

Browse files
committed
feat: add better error handling if story doesn't exist
1 parent 61be07b commit 54bdfc1

File tree

2 files changed

+18
-4
lines changed

2 files changed

+18
-4
lines changed

src/browser/page2layers.js

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,10 @@ export const getSymbol = ({
2121
nodes = document.querySelector(querySelector);
2222
}
2323

24+
if (!nodes) {
25+
return null;
26+
}
27+
2428
const layer = nodeTreeToSketchGroup(nodes, {
2529
getGroupName: getNodeName,
2630
getRectangleName: getNodeName

src/server/Story2sketch.js

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -163,7 +163,7 @@ export default class Story2sketch {
163163
}
164164

165165
// Initialize an array per viewport based on the number of stories
166-
for (const {id} of this.sortedViewports) {
166+
for (const { id } of this.sortedViewports) {
167167
this.symbolsByViewport[id] = Array(this.storyCount);
168168
}
169169

@@ -208,9 +208,19 @@ export default class Story2sketch {
208208

209209
const symbol = JSON.parse(symbolJson);
210210

211-
symbol.symbolID = `${name}:${id}`;
212-
213-
symbolByViewport[id] = symbol;
211+
if (symbol) {
212+
symbol.symbolID = `${name}:${id}`;
213+
214+
symbolByViewport[id] = symbol;
215+
} else {
216+
console.warn(
217+
chalk.yellow(
218+
` WARNING: No matching node for "${name}" using querySelector ${
219+
this.querySelector
220+
} on viewport ${id}`
221+
)
222+
);
223+
}
214224
}
215225

216226
this.logProgress(name);

0 commit comments

Comments
 (0)