Missing Trait variant gives a poor error
Closed this issue · 0 comments
mlhaufe commented
Error:
Uncaught Error: Every variant must have a trait defined
Offending code:
const Shape = Data({
Circle: ["radius"],
Ellipse: ["r1", "r2"],
Rectangle: ["side1", "side2"],
RightTriangle: ["base", "height"],
Polygon: ["vertices"],
Square: ["side"]
});
const shapeToSvg = Trait(Shape, {
Circle: ({ radius }, container) => {
const [x, y] = transOrigin(container, [radius, radius]);
return circle({ cx: x, cy: y, r: radius })
},
Ellipse: ({ r1, r2 }, container) => {
const [x, y] = transOrigin(container, [r1, r2]);
return ellipse({ cx: x, cy: y, rx: r1, ry: r2 })
},
Rectangle: ({ side1, side2 }, container) => {
const s12 = div(side1, 2),
s22 = div(side2, 2)
return polygon(
transVertices(container, [-s12, -s22], [s12, -s22], [s12, s22], [-s12, s22])
)
},
RightTriangle: ({ base, height }, container) => {
const b2 = div(base, 2),
h2 = div(height, 2)
return polygon(transVertices(container, [0, -h2], [b2, h2], [-b2, h2]))
}
})
A better message would be:
Invalid Trait declaration. Missing definition for 'Polygon'