Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

RUM-917 Improve telemetry of type mismatch #1863

Merged
merged 2 commits into from
Jun 6, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -41,17 +41,32 @@ extension SRWireframe: Diffable {
return true
}
}

var type: String {
switch self {
case let (.shapeWireframe(value)):
return value.type
case let (.textWireframe(value)):
return value.type
case let (.imageWireframe(value)):
return value.type
case let (.placeholderWireframe(value)):
return value.type
case let (.webviewWireframe(value)):
return value.type
}
}
}

// MARK: - Resolving Mutations

internal typealias WireframeMutation = SRIncrementalSnapshotRecord.Data.MutationData.Updates

internal enum WireframeMutationError: Error {
internal enum WireframeMutationError: Error, Equatable {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I believe this enum is automatically conforming to Equatable since the associated values you added are String. I don't think it's an issue to add it explicitly, but I was wondering if I missed anything here?

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Assertions in test were complaining about it. I think that once enum has associated values it needs to be explicitly specified

/// Indicates an attempt of computing mutation for wireframes that have different `id`.
case idMismatch
/// Indicates an attempt of computing mutation for wireframes that have different type.
case typeMismatch
case typeMismatch(fromType: String, toType: String)
}

internal protocol MutableWireframe {
Expand Down Expand Up @@ -84,8 +99,13 @@ extension SRWireframe: MutableWireframe {
extension SRShapeWireframe: MutableWireframe {
func mutations(from otherWireframe: SRWireframe) throws -> WireframeMutation {
guard case .shapeWireframe(let other) = otherWireframe else {
throw WireframeMutationError.typeMismatch
throw WireframeMutationError.typeMismatch(
fromType: otherWireframe.type,
toType: type
)
}
// print string of enum of otherWireframe

guard other.id == id else {
throw WireframeMutationError.idMismatch
}
Expand All @@ -108,7 +128,10 @@ extension SRShapeWireframe: MutableWireframe {
extension SRPlaceholderWireframe: MutableWireframe {
func mutations(from otherWireframe: SRWireframe) throws -> WireframeMutation {
guard case .placeholderWireframe(let other) = otherWireframe else {
throw WireframeMutationError.typeMismatch
throw WireframeMutationError.typeMismatch(
fromType: otherWireframe.type,
toType: type
)
}
guard other.id == id else {
throw WireframeMutationError.idMismatch
Expand All @@ -130,7 +153,10 @@ extension SRPlaceholderWireframe: MutableWireframe {
extension SRImageWireframe: MutableWireframe {
func mutations(from otherWireframe: SRWireframe) throws -> WireframeMutation {
guard case .imageWireframe(let other) = otherWireframe else {
throw WireframeMutationError.typeMismatch
throw WireframeMutationError.typeMismatch(
fromType: otherWireframe.type,
toType: type
)
}
guard other.id == id else {
throw WireframeMutationError.idMismatch
Expand All @@ -157,7 +183,10 @@ extension SRImageWireframe: MutableWireframe {
extension SRTextWireframe: MutableWireframe {
func mutations(from otherWireframe: SRWireframe) throws -> WireframeMutation {
guard case .textWireframe(let other) = otherWireframe else {
throw WireframeMutationError.typeMismatch
throw WireframeMutationError.typeMismatch(
fromType: otherWireframe.type,
toType: type
)
}
guard other.id == id else {
throw WireframeMutationError.idMismatch
Expand All @@ -184,7 +213,10 @@ extension SRTextWireframe: MutableWireframe {
extension SRWebviewWireframe: MutableWireframe {
func mutations(from otherWireframe: SRWireframe) throws -> WireframeMutation {
guard case .webviewWireframe(let other) = otherWireframe else {
throw WireframeMutationError.typeMismatch
throw WireframeMutationError.typeMismatch(
fromType: otherWireframe.type,
toType: type
)
}
guard other.id == id, other.slotId == slotId else {
throw WireframeMutationError.idMismatch
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -97,7 +97,7 @@ class RecordsBuilderTests: XCTestCase {
telemetry.description,
"""
Telemetry logs:
- [error] [SR] Failed to create incremental record - typeMismatch, kind: WireframeMutationError, stack: typeMismatch
- [error] [SR] Failed to create incremental record - typeMismatch(fromType: "shape", toType: "text"), kind: WireframeMutationError, stack: typeMismatch(fromType: "shape", toType: "text")
"""
)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -117,7 +117,13 @@ class DiffSRWireframes: XCTestCase {
try wireframes.forEach { wireframeA, wireframeB in
XCTAssertThrowsError(try wireframeB.mutations(from: wireframeA)) { error in
// Then
XCTAssertEqual(error as? WireframeMutationError, WireframeMutationError.typeMismatch)
XCTAssertEqual(
error as? WireframeMutationError,
WireframeMutationError.typeMismatch(
fromType: wireframeA.type,
toType: wireframeB.type
)
)
}
}
}
Expand Down