Skip to content

Commit

Permalink
[pigeon] Simplify localizedDescription of PigeonError in Swift
Browse files Browse the repository at this point in the history
  • Loading branch information
bc-lee committed Apr 25, 2024
1 parent d8968d7 commit c2beea1
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 24 deletions.
10 changes: 1 addition & 9 deletions packages/pigeon/example/app/ios/Runner/Messages.g.swift
Expand Up @@ -27,16 +27,8 @@ class PigeonError: Swift.Error {
}

var localizedDescription: String {
let detailsDescription: String
if let convertibleObject = details as? CustomStringConvertible {
detailsDescription = convertibleObject.description
} else if let _ = details {
detailsDescription = "<non-convertible object>"
} else {
detailsDescription = "<nil>"
}
return
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(detailsDescription)"
"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"
}
}

Expand Down
18 changes: 3 additions & 15 deletions packages/pigeon/lib/swift_generator.dart
Expand Up @@ -928,23 +928,11 @@ private func nilOrValue<T>(_ value: Any?) -> T? {
indent.newln();
indent.writeln('var localizedDescription: String {');
indent.nest(1, () {
indent.writeln('let detailsDescription: String');
indent.writeln(
'if let convertibleObject = details as? CustomStringConvertible {');
indent.nest(1, () {
indent.writeln('detailsDescription = convertibleObject.description');
});
indent.writeln('} else if let _ = details {');
indent.writeln('return');
indent.nest(1, () {
indent.writeln('detailsDescription = "<non-convertible object>"');
});
indent.writeln('} else {');
indent.nest(1, () {
indent.writeln('detailsDescription = "<nil>"');
indent.writeln(
r'"PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(details ?? "<nil>")"');
});
indent.writeln('}');
indent.writeln(
r'return "PigeonError(code: \(code), message: \(message ?? "<nil>"), details: \(detailsDescription)"');
});
indent.write('}');
});
Expand Down

0 comments on commit c2beea1

Please sign in to comment.