diff --git a/Sources/DisplayListDescription/DisplayListDescriptionConverter.swift b/Sources/DisplayListDescription/DisplayListDescriptionConverter.swift index 8243619..4244bd2 100644 --- a/Sources/DisplayListDescription/DisplayListDescriptionConverter.swift +++ b/Sources/DisplayListDescription/DisplayListDescriptionConverter.swift @@ -415,8 +415,17 @@ private struct Renderer { let children = directLists(in: item) if children.contains(where: { $0.head == "content-seed" }) { guard let content = children.first(where: { ContentKind(head: $0.head) != nil }) else { + if let unsupportedHead = children.first(where: { + $0.head != "frame" && $0.head != "content-seed" + })?.head { + var message = "Item identity \(identity) contains unsupported DisplayList content “\(unsupportedHead)”." + if let suggestion = ContentKind.suggestedHead(for: unsupportedHead) { + message += " Did you mean “\(suggestion)”?" + } + throw DisplayListDescriptionError.unsupported(message: message) + } throw DisplayListDescriptionError.unsupported( - message: "This item contains content-seed but no supported content value." + message: "Item identity \(identity) contains content-seed but no content value." ) } rendered.include(try renderContent(content)) @@ -647,6 +656,15 @@ private enum ContentKind { case view case placeholder + static func suggestedHead(for head: String) -> String? { + switch head { + case "chameleonColor": "chameleon-color" + case "platformView": "platform-view" + case "platformLayer": "platform-layer" + default: nil + } + } + init?(head: String?) { switch head { case "backdrop": self = .backdrop diff --git a/Tests/DisplayListDescriptionTests/DisplayListDescriptionConverterTests.swift b/Tests/DisplayListDescriptionTests/DisplayListDescriptionConverterTests.swift index fa15021..4926d0b 100644 --- a/Tests/DisplayListDescriptionTests/DisplayListDescriptionConverterTests.swift +++ b/Tests/DisplayListDescriptionTests/DisplayListDescriptionConverterTests.swift @@ -207,6 +207,25 @@ final class DisplayListDescriptionConverterTests: XCTestCase { } } + func testReportsUnsupportedContentNameAndSuggestedSpelling() { + let description = """ + (display-list + (item #:identity 4 #:version 2 + (frame {{12, 8.3333333333333339}, {164, 40}}) + (content-seed 5) + (platformView DemoPlatformViewFactory()))) + """ + + XCTAssertThrowsError(try DisplayListDescriptionConverter.convert(description)) { error in + XCTAssertEqual( + error as? DisplayListDescriptionError, + .unsupported( + message: "Item identity 4 contains unsupported DisplayList content “platformView”. Did you mean “platform-view”?" + ) + ) + } + } + private func utf16Slice(_ text: String, _ start: Int, _ end: Int) -> String { let codeUnits = Array(text.utf16) return String(decoding: codeUnits[start..