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

Improve error message for missing reflection data #2038

Merged
merged 2 commits into from
Sep 2, 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
18 changes: 12 additions & 6 deletions Sources/GRPCReflectionService/Server/ReflectionService.swift
Original file line number Diff line number Diff line change
Expand Up @@ -40,6 +40,8 @@ public final class ReflectionService: CallHandlerProvider, Sendable {
/// - Parameter fileURLs: The URLs of the files containing serialized reflection data.
/// - Parameter version: The version of the reflection service to create.
///
/// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends
/// on them.
/// - Throws: When a file can't be read from disk or parsed.
public convenience init(reflectionDataFileURLs fileURLs: [URL], version: Version) throws {
let filePaths: [String]
Expand All @@ -64,6 +66,8 @@ public final class ReflectionService: CallHandlerProvider, Sendable {
/// - Parameter filePaths: The paths to files containing serialized reflection data.
/// - Parameter version: The version of the reflection service to create.
///
/// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends
/// on them.
/// - Throws: When a file can't be read from disk or parsed.
public init(reflectionDataFilePaths filePaths: [String], version: Version) throws {
let fileDescriptorProtos = try ReflectionService.readSerializedFileDescriptorProtos(
Expand Down Expand Up @@ -218,12 +222,14 @@ internal struct ReflectionServiceData: Sendable {
let serializedFileDescriptorProto = protoData.serializedFileDescriptorProto
serializedFileDescriptorProtos.append(serializedFileDescriptorProto)
} else {
return .failure(
GRPCStatus(
code: .notFound,
message: "The provided file or a dependency of the provided file could not be found."
)
)
let base = "No reflection data for '\(currentFileName)'"
let message: String
if fileName == currentFileName {
message = base + "."
} else {
message = base + " which is a dependency of '\(fileName)'."
}
return .failure(GRPCStatus(code: .notFound, message: message))
}
visited.insert(currentFileName)
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -287,7 +287,7 @@ final class ReflectionServiceIntegrationTests: GRPCTestCase {
XCTAssertEqual(message.errorResponse.errorCode, Int32(GRPCStatus.Code.notFound.rawValue))
XCTAssertEqual(
message.errorResponse.errorMessage,
"The provided file or a dependency of the provided file could not be found."
"No reflection data for 'invalidFileName.proto'."
)
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -349,7 +349,7 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
status,
GRPCStatus(
code: .notFound,
message: "The provided file or a dependency of the provided file could not be found."
message: "No reflection data for 'invalid.proto'."
)
)
}
Expand All @@ -368,7 +368,8 @@ final class ReflectionServiceUnitTests: GRPCTestCase {
status,
GRPCStatus(
code: .notFound,
message: "The provided file or a dependency of the provided file could not be found."
message:
"No reflection data for 'invalidDependency' which is a dependency of 'bar1.proto'."
)
)
}
Expand Down
Loading