Skip to content

Commit e9b00ea

Browse files
committed
Detect geometry parsing errors
1 parent 74b59c3 commit e9b00ea

File tree

3 files changed

+17
-7
lines changed

3 files changed

+17
-7
lines changed

ShapeScript/EvaluationContext.swift

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -282,6 +282,10 @@ extension EvaluationContext {
282282
children.append(.mesh(geometry))
283283
return
284284
}
285+
} catch let error as ImportError {
286+
throw RuntimeErrorType.fileParsingError(
287+
for: path, at: url, message: error.message
288+
)
285289
} catch {
286290
let description = (error as NSError)
287291
.userInfo[NSLocalizedDescriptionKey] as? String ?? "\(error)"

ShapeScript/Scene+SceneKit.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -238,19 +238,25 @@ public extension Material {
238238
}
239239

240240
public extension Geometry {
241-
convenience init(scnNode: SCNNode) {
242-
var type = GeometryType.group
243-
if let scnGeometry = scnNode.geometry, let mesh = Mesh(
244-
scnGeometry, materialLookup: Material.init(scnMaterial:)
245-
) {
241+
convenience init(scnNode: SCNNode) throws {
242+
let type: GeometryType
243+
if let scnGeometry = scnNode.geometry {
244+
guard let mesh = Mesh(
245+
scnGeometry,
246+
materialLookup: Material.init(scnMaterial:)
247+
) else {
248+
throw ImportError.unknownError
249+
}
246250
type = .mesh(mesh)
251+
} else {
252+
type = .group
247253
}
248254
self.init(
249255
type: type,
250256
name: scnNode.name,
251257
transform: .transform(from: scnNode),
252258
material: .default,
253-
children: scnNode.childNodes.map(Geometry.init(scnNode:)),
259+
children: try scnNode.childNodes.map(Geometry.init(scnNode:)),
254260
sourceLocation: nil
255261
)
256262
}

Viewer/Document.swift

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -540,7 +540,7 @@ class Document: NSDocument, EvaluationDelegate {
540540
.createNormalsIfAbsent: true,
541541
.convertToYUp: true,
542542
])
543-
return Geometry(scnNode: scene.rootNode)
543+
return try Geometry(scnNode: scene.rootNode)
544544
}
545545

546546
func debugLog(_ values: [AnyHashable]) {

0 commit comments

Comments
 (0)