Make creature error messages easier to read.
rodzic
87affa0a4c
commit
5a5030ceb6
|
@ -20,20 +20,22 @@ function getAttachmentPoint(
|
||||||
): PointWithNormal {
|
): PointWithNormal {
|
||||||
const { specs } = s;
|
const { specs } = s;
|
||||||
if (!specs) {
|
if (!specs) {
|
||||||
throw new Error(`Symbol ${s.name} has no specs!`);
|
throw new AttachmentPointError(`Symbol ${s.name} has no specs.`);
|
||||||
}
|
}
|
||||||
const points = specs[type];
|
const points = specs[type];
|
||||||
if (!(points && points.length > idx)) {
|
if (!(points && points.length > idx)) {
|
||||||
throw new Error(
|
throw new AttachmentPointError(
|
||||||
`Expected symbol ${s.name} to have at least ${
|
`Expected symbol ${s.name} to have at least ${
|
||||||
idx + 1
|
idx + 1
|
||||||
} ${type} attachment point(s)!`
|
} ${type} attachment point(s).`
|
||||||
);
|
);
|
||||||
}
|
}
|
||||||
|
|
||||||
return points[idx];
|
return points[idx];
|
||||||
}
|
}
|
||||||
|
|
||||||
|
class AttachmentPointError extends Error {}
|
||||||
|
|
||||||
function safeGetAttachmentPoint(
|
function safeGetAttachmentPoint(
|
||||||
s: SvgSymbolData,
|
s: SvgSymbolData,
|
||||||
type: AttachmentPointType,
|
type: AttachmentPointType,
|
||||||
|
@ -42,7 +44,11 @@ function safeGetAttachmentPoint(
|
||||||
try {
|
try {
|
||||||
return getAttachmentPoint(s, type, idx);
|
return getAttachmentPoint(s, type, idx);
|
||||||
} catch (e) {
|
} catch (e) {
|
||||||
console.error(e);
|
if (e instanceof AttachmentPointError) {
|
||||||
|
console.log(e.message);
|
||||||
|
} else {
|
||||||
|
throw e;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return null;
|
return null;
|
||||||
|
@ -132,8 +138,8 @@ const NestedCreatureSymbol: React.FC<ChildCreatureSymbolProps> = ({
|
||||||
for (let nestIndex of indices) {
|
for (let nestIndex of indices) {
|
||||||
const parentNest = (parent.specs?.nesting ?? [])[nestIndex];
|
const parentNest = (parent.specs?.nesting ?? [])[nestIndex];
|
||||||
if (!parentNest) {
|
if (!parentNest) {
|
||||||
console.error(
|
console.log(
|
||||||
`Parent symbol ${parent.name} has no nesting index ${nestIndex}!`
|
`Parent symbol ${parent.name} has no nesting index ${nestIndex}.`
|
||||||
);
|
);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
|
|
Ładowanie…
Reference in New Issue