Skip to content

Commit 95430b9

Browse files
authored
Improve error message for missing reflection data (#2038)
Motivation: The message for missing reflection data isn't very helpful as it doesn't indicate what reflection data is missing. Modifications: - Improve the error message - Add note about well-known-types Result: Clearer error message
1 parent 2cef047 commit 95430b9

File tree

1 file changed

+12
-6
lines changed

1 file changed

+12
-6
lines changed

Sources/GRPCReflectionService/Server/ReflectionService.swift

Lines changed: 12 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,8 @@ public final class ReflectionService: CallHandlerProvider, Sendable {
4040
/// - Parameter fileURLs: The URLs of the files containing serialized reflection data.
4141
/// - Parameter version: The version of the reflection service to create.
4242
///
43+
/// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends
44+
/// on them.
4345
/// - Throws: When a file can't be read from disk or parsed.
4446
public convenience init(reflectionDataFileURLs fileURLs: [URL], version: Version) throws {
4547
let filePaths: [String]
@@ -64,6 +66,8 @@ public final class ReflectionService: CallHandlerProvider, Sendable {
6466
/// - Parameter filePaths: The paths to files containing serialized reflection data.
6567
/// - Parameter version: The version of the reflection service to create.
6668
///
69+
/// - Note: Reflection data for well-known-types must be provided if any of your reflection data depends
70+
/// on them.
6771
/// - Throws: When a file can't be read from disk or parsed.
6872
public init(reflectionDataFilePaths filePaths: [String], version: Version) throws {
6973
let fileDescriptorProtos = try ReflectionService.readSerializedFileDescriptorProtos(
@@ -218,12 +222,14 @@ internal struct ReflectionServiceData: Sendable {
218222
let serializedFileDescriptorProto = protoData.serializedFileDescriptorProto
219223
serializedFileDescriptorProtos.append(serializedFileDescriptorProto)
220224
} else {
221-
return .failure(
222-
GRPCStatus(
223-
code: .notFound,
224-
message: "The provided file or a dependency of the provided file could not be found."
225-
)
226-
)
225+
let base = "No reflection data for '\(currentFileName)'"
226+
let message: String
227+
if fileName == currentFileName {
228+
message = base + "."
229+
} else {
230+
message = base + " which is a dependency of '\(fileName)'."
231+
}
232+
return .failure(GRPCStatus(code: .notFound, message: message))
227233
}
228234
visited.insert(currentFileName)
229235
}

0 commit comments

Comments
 (0)