[ https://issues.apache.org/jira/browse/THRIFT-3773?page=com.atlassian.jira.plugin.system.issuetabpanels:comment-tabpanel&focusedCommentId=15486444#comment-15486444 ]
ASF GitHub Bot commented on THRIFT-3773: ---------------------------------------- Github user SirWellington commented on a diff in the pull request: https://github.com/apache/thrift/pull/1084#discussion_r78503326 --- Diff: lib/swift/Sources/TApplicationError.swift --- @@ -0,0 +1,157 @@ +/* +* Licensed to the Apache Software Foundation (ASF) under one +* or more contributor license agreements. See the NOTICE file +* distributed with this work for additional information +* regarding copyright ownership. The ASF licenses this file +* to you under the Apache License, Version 2.0 (the +* "License"); you may not use this file except in compliance +* with the License. You may obtain a copy of the License at +* +* http://www.apache.org/licenses/LICENSE-2.0 +* +* Unless required by applicable law or agreed to in writing, +* software distributed under the License is distributed on an +* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +* KIND, either express or implied. See the License for the +* specific language governing permissions and limitations +* under the License. +*/ + + +public struct TApplicationError : TError { + public enum Code : TErrorCode { + case unknown + case unknownMethod(methodName: String?) + case invalidMessageType + case wrongMethodName(methodName: String?) + case badSequenceId + case missingResult(methodName: String?) + case internalError + case protocolError + case invalidTransform + case invalidProtocol + case unsupportedClientType + + + /// Initialize a TApplicationError with a Thrift error code + /// Normally this would be achieved with RawRepresentable however + /// by doing this we can allow for associated properties on enum cases for + /// case specific context data in a Swifty, type-safe manner. + /// + /// - parameter thriftErrorCode: Integer TApplicationError(exception) error code. + /// Default to 0 (.unknown) + public init(thriftErrorCode: Int) { + switch thriftErrorCode { + case 1: self = .unknownMethod(methodName: nil) + case 2: self = .invalidMessageType + case 3: self = .wrongMethodName(methodName: nil) + case 4: self = .badSequenceId + case 5: self = .missingResult(methodName: nil) + case 6: self = .internalError + case 7: self = .protocolError + case 8: self = .invalidProtocol + case 9: self = .invalidTransform + case 10: self = .unsupportedClientType + default: self = .unknown + } + } + public var thriftErrorCode: Int { + switch self { + case .unknown: return 0 + case .unknownMethod: return 1 + case .invalidMessageType: return 2 + case .wrongMethodName: return 3 + case .badSequenceId: return 4 + case .missingResult: return 5 + case .internalError: return 6 + case .protocolError: return 7 + case .invalidProtocol: return 8 + case .invalidTransform: return 9 + case .unsupportedClientType: return 10 + } + } + + public var description: String { + /// Output "for #methodName" if method is not nil else empty + let methodUnwrap: (String?) -> String = { method in + return "\(method == nil ? "" : " for \(method ?? "")")" + } + switch self { + case .unknown: return "Unknown TApplicationError" + case .unknownMethod(let method): return "Unknown Method\(methodUnwrap(method))" + case .invalidMessageType: return "Invalid Message Type" + case .wrongMethodName(let method): return "Wrong Method Name\(methodUnwrap(method))" + case .badSequenceId: return "Bad Sequence ID" + case .missingResult(let method): return "Missing Result\(methodUnwrap(method))" + case .internalError: return "Internal Error" + case .protocolError: return "Protocol Error" + case .invalidProtocol: return "Invalid Protocol" + case .invalidTransform: return "Invalid Transform" + case .unsupportedClientType: return "Unsupported Client Type" + } + } + } + + public init() { } + + public init(thriftErrorCode code: Int, message: String?=nil) { --- End diff -- Might wanna space out the `String?=nil` to `String? = nil` > Swift Library > ------------- > > Key: THRIFT-3773 > URL: https://issues.apache.org/jira/browse/THRIFT-3773 > Project: Thrift > Issue Type: New Feature > Components: Swift - Library > Reporter: Thomas Bartelmess > > We already have the option to generate Swift code in the Cocoa compiler, > however large parts of the (Objective-C) Cocoa Library still depend on Cocoa > and Objective-C. > It would be good to have a native Swift library that doesn't depend on the > Cocoa libraries. > Design goals: > - Fully compatible with the code that is currently generated by the Cocoa > compiler (both Objective-C and Swift). > - Ability to run on Linux > - Pure Swift, no Objective-C code. > - No dependencies on closed source apple libraries > - Keep the same interface, so that the library is compatible with the code > the current cocoa compiler generates > - Better server support that the current Objective-C library. > - Follow the new Swift packaging format to be compatible with the Swift > Package manager -- This message was sent by Atlassian JIRA (v6.3.4#6332)