Skip to content

Commit

Permalink
Throwing parsers (as opposed to trapping)
Browse files Browse the repository at this point in the history
  • Loading branch information
czechboy0 committed Jun 17, 2016
1 parent 840955c commit be980ce
Show file tree
Hide file tree
Showing 40 changed files with 320 additions and 257 deletions.
2 changes: 1 addition & 1 deletion Podfile
Expand Up @@ -2,7 +2,7 @@
use_frameworks!

def utils
pod 'BuildaUtils', '~> 0.2.3'
pod 'BuildaUtils', '~> 0.3.2'
end

def tests
Expand Down
10 changes: 5 additions & 5 deletions Podfile.lock
@@ -1,12 +1,12 @@
PODS:
- BuildaUtils (0.2.8):
- BuildaUtils (0.3.2):
- SwiftSafe (~> 0.1)
- DVR (0.0.4-czechboy0)
- Nimble (3.1.0)
- SwiftSafe (0.1)

DEPENDENCIES:
- BuildaUtils (~> 0.2.3)
- BuildaUtils (~> 0.3.2)
- DVR (from `https://github.com/czechboy0/DVR.git`, tag `v0.0.5-czechboy0`)
- Nimble (from `https://github.com/Quick/Nimble.git`, commit `b9256b0bdecc4ef1f659b7663dcd3aab6f43fb5f`)

Expand All @@ -27,11 +27,11 @@ CHECKOUT OPTIONS:
:git: https://github.com/Quick/Nimble.git

SPEC CHECKSUMS:
BuildaUtils: 0974c128ace30916b9b9429e8585c1c6402593dd
BuildaUtils: 1c6bf3a28948c3aae242171abf2474cd4746a2d1
DVR: 386f347071f55f3f9105239db6764483009ec875
Nimble: eb2a9b164b9a3f16df6581c692a0bfced7d072a4
SwiftSafe: 77ffd12b02678790bec1ef56a2d14ec5036f1fd6

PODFILE CHECKSUM: 67beeffd0d8e791afcfda6d3008101471799f0d9
PODFILE CHECKSUM: 2d0c8056afb549d3590407decab7568949826dc2

COCOAPODS: 1.0.0.beta.3
COCOAPODS: 1.0.1
30 changes: 15 additions & 15 deletions XcodeServerSDK.xcodeproj/project.pbxproj
Expand Up @@ -419,12 +419,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 3A7B48D01B2A5AC40077ABEA /* Build configuration list for PBXNativeTarget "XcodeServerSDK" */;
buildPhases = (
608915A9B6E46B97563824D6 /* Check Pods Manifest.lock */,
608915A9B6E46B97563824D6 /* [CP] Check Pods Manifest.lock */,
3A7B48B51B2A5AC40077ABEA /* Sources */,
3A7B48B61B2A5AC40077ABEA /* Frameworks */,
3A7B48B71B2A5AC40077ABEA /* Headers */,
3A7B48B81B2A5AC40077ABEA /* Resources */,
BEE968EB4C2D07460226F3D4 /* Copy Pods Resources */,
BEE968EB4C2D07460226F3D4 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand All @@ -439,12 +439,12 @@
isa = PBXNativeTarget;
buildConfigurationList = 3A7B48D31B2A5AC40077ABEA /* Build configuration list for PBXNativeTarget "XcodeServerSDKTests" */;
buildPhases = (
729BDC3F596341C91349E495 /* Check Pods Manifest.lock */,
729BDC3F596341C91349E495 /* [CP] Check Pods Manifest.lock */,
3A7B48C11B2A5AC40077ABEA /* Sources */,
3A7B48C21B2A5AC40077ABEA /* Frameworks */,
3A7B48C31B2A5AC40077ABEA /* Resources */,
0C8961B6A622E40751509352 /* Embed Pods Frameworks */,
3B64028920C09D09701D0715 /* Copy Pods Resources */,
0C8961B6A622E40751509352 /* [CP] Embed Pods Frameworks */,
3B64028920C09D09701D0715 /* [CP] Copy Pods Resources */,
);
buildRules = (
);
Expand Down Expand Up @@ -528,74 +528,74 @@
/* End PBXResourcesBuildPhase section */

/* Begin PBXShellScriptBuildPhase section */
0C8961B6A622E40751509352 /* Embed Pods Frameworks */ = {
0C8961B6A622E40751509352 /* [CP] Embed Pods Frameworks */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Embed Pods Frameworks";
name = "[CP] Embed Pods Frameworks";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XcodeServerSDKTests/Pods-XcodeServerSDKTests-frameworks.sh\"\n";
showEnvVarsInLog = 0;
};
3B64028920C09D09701D0715 /* Copy Pods Resources */ = {
3B64028920C09D09701D0715 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "\"${SRCROOT}/Pods/Target Support Files/Pods-XcodeServerSDKTests/Pods-XcodeServerSDKTests-resources.sh\"\n";
showEnvVarsInLog = 0;
};
608915A9B6E46B97563824D6 /* Check Pods Manifest.lock */ = {
608915A9B6E46B97563824D6 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
729BDC3F596341C91349E495 /* Check Pods Manifest.lock */ = {
729BDC3F596341C91349E495 /* [CP] Check Pods Manifest.lock */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Check Pods Manifest.lock";
name = "[CP] Check Pods Manifest.lock";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
shellPath = /bin/sh;
shellScript = "diff \"${PODS_ROOT}/../Podfile.lock\" \"${PODS_ROOT}/Manifest.lock\" > /dev/null\nif [[ $? != 0 ]] ; then\n cat << EOM\nerror: The sandbox is not in sync with the Podfile.lock. Run 'pod install' or update your CocoaPods installation.\nEOM\n exit 1\nfi\n";
showEnvVarsInLog = 0;
};
BEE968EB4C2D07460226F3D4 /* Copy Pods Resources */ = {
BEE968EB4C2D07460226F3D4 /* [CP] Copy Pods Resources */ = {
isa = PBXShellScriptBuildPhase;
buildActionMask = 2147483647;
files = (
);
inputPaths = (
);
name = "Copy Pods Resources";
name = "[CP] Copy Pods Resources";
outputPaths = (
);
runOnlyForDeploymentPostprocessing = 0;
Expand Down
22 changes: 16 additions & 6 deletions XcodeServerSDK/API Routes/XcodeServer+Bot.swift
Expand Up @@ -80,8 +80,10 @@ extension XcodeServer {
}

if let body = (body as? NSDictionary)?["results"] as? NSArray {
let bots: [Bot] = XcodeServerArray(body)
completion(bots: bots, error: nil)
let (result, error): ([Bot]?, NSError?) = unthrow {
return try XcodeServerArray(body)
}
completion(bots: result, error: error)
} else {
completion(bots: nil, error: Error.withInfo("Wrong data returned: \(body)"))
}
Expand Down Expand Up @@ -109,8 +111,10 @@ extension XcodeServer {
}

if let body = body as? NSDictionary {
let bot = Bot(json: body)
completion(bot: bot, error: nil)
let (result, error): (Bot?, NSError?) = unthrow {
return try Bot(json: body)
}
completion(bot: result, error: error)
} else {
completion(bot: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down Expand Up @@ -205,8 +209,14 @@ extension XcodeServer {
return
}

let bot = Bot(json: dictBody)
completion(response: XcodeServer.CreateBotResponse.Success(bot: bot))
let (result, error): (Bot?, NSError?) = unthrow {
return try Bot(json: dictBody)
}
if let err = error {
completion(response: XcodeServer.CreateBotResponse.Error(error: err))
} else {
completion(response: XcodeServer.CreateBotResponse.Success(bot: result!))
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions XcodeServerSDK/API Routes/XcodeServer+Device.swift
Expand Up @@ -28,8 +28,10 @@ extension XcodeServer {
}

if let array = (body as? NSDictionary)?["results"] as? NSArray {
let devices: [Device] = XcodeServerArray(array)
completion(devices: devices, error: error)
let (result, error): ([Device]?, NSError?) = unthrow {
return try XcodeServerArray(array)
}
completion(devices: result, error: error)
} else {
completion(devices: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down
38 changes: 24 additions & 14 deletions XcodeServerSDK/API Routes/XcodeServer+Integration.swift
Expand Up @@ -40,8 +40,10 @@ extension XcodeServer {
}

if let body = (body as? NSDictionary)?["results"] as? NSArray {
let integrations: [Integration] = XcodeServerArray(body)
completion(integrations: integrations, error: nil)
let (result, error): ([Integration]?, NSError?) = unthrow {
return try XcodeServerArray(body)
}
completion(integrations: result, error: error)
} else {
completion(integrations: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down Expand Up @@ -69,8 +71,10 @@ extension XcodeServer {
}

if let body = body as? NSDictionary {
let integration = Integration(json: body)
completion(integration: integration, error: nil)
let (result, error): (Integration?, NSError?) = unthrow {
return try Integration(json: body)
}
completion(integration: result, error: error)
} else {
completion(integration: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down Expand Up @@ -100,8 +104,10 @@ extension XcodeServer {
return
}

let integrations: [Integration] = XcodeServerArray(integrationsBody)
completion(integrations: integrations, error: nil)
let (result, error): ([Integration]?, NSError?) = unthrow {
return try XcodeServerArray(integrationsBody)
}
completion(integrations: result, error: error)
}
}

Expand Down Expand Up @@ -132,8 +138,10 @@ extension XcodeServer {
return
}

let integration = Integration(json: integrationBody)
completion(integration: integration, error: nil)
let (result, error): (Integration?, NSError?) = unthrow {
return try Integration(json: integrationBody)
}
completion(integration: result, error: error)
}
}

Expand Down Expand Up @@ -186,9 +194,10 @@ extension XcodeServer {
return
}

let integrationCommits = IntegrationCommits(json: integrationCommitsBody[0] as! NSDictionary)
completion(integrationCommits: integrationCommits, error: nil)

let (result, error): (IntegrationCommits?, NSError?) = unthrow {
return try IntegrationCommits(json: integrationCommitsBody[0] as! NSDictionary)
}
completion(integrationCommits: result, error: error)
}

}
Expand Down Expand Up @@ -218,9 +227,10 @@ extension XcodeServer {
return
}

let integrationIssues = IntegrationIssues(json: integrationIssuesBody)
completion(integrationIssues: integrationIssues, error: nil)

let (result, error): (IntegrationIssues?, NSError?) = unthrow {
return try IntegrationIssues(json: integrationIssuesBody)
}
completion(integrationIssues: result, error: error)
}

}
Expand Down
11 changes: 8 additions & 3 deletions XcodeServerSDK/API Routes/XcodeServer+LiveUpdates.swift
Expand Up @@ -107,11 +107,16 @@ extension XcodeServer {
self.sendRequest(state, params: params) { [weak self] (message) -> () in

let packets = SocketIOHelper.parsePackets(message)
self?.handlePackets(packets, state: state)

do {
try self?.handlePackets(packets, state: state)
} catch {
state.error(error)
}
}
}

private func handlePackets(packets: [SocketIOPacket], state: LiveUpdateState) {
private func handlePackets(packets: [SocketIOPacket], state: LiveUpdateState) throws {

//check for errors
if let lastPacket = packets.last where lastPacket.type == .Error {
Expand All @@ -129,7 +134,7 @@ extension XcodeServer {
//we good?
let events = packets.filter { $0.type == .Event }
let validEvents = events.filter { $0.jsonPayload != nil }
let messages = validEvents.map { LiveUpdateMessage(json: $0.jsonPayload!) }
let messages = try validEvents.map { try LiveUpdateMessage(json: $0.jsonPayload!) }
if messages.count > 0 {
state.messageHandler?(messages: messages)
}
Expand Down
6 changes: 4 additions & 2 deletions XcodeServerSDK/API Routes/XcodeServer+Platform.swift
Expand Up @@ -28,8 +28,10 @@ extension XcodeServer {
}

if let array = (body as? NSDictionary)?["results"] as? NSArray {
let platforms: [DevicePlatform] = XcodeServerArray(array)
completion(platforms: platforms, error: error)
let (result, error): ([DevicePlatform]?, NSError?) = unthrow {
return try XcodeServerArray(array)
}
completion(platforms: result, error: error)
} else {
completion(platforms: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down
16 changes: 12 additions & 4 deletions XcodeServerSDK/API Routes/XcodeServer+Repository.swift
Expand Up @@ -31,8 +31,10 @@ extension XcodeServer {
return
}

let repos: [Repository] = XcodeServerArray(repositoriesBody)
completion(repositories: repos, error: nil)
let (result, error): ([Repository]?, NSError?) = unthrow {
return try XcodeServerArray(repositoriesBody)
}
completion(repositories: result, error: error)
}
}

Expand Down Expand Up @@ -89,8 +91,14 @@ extension XcodeServer {
return
}

let repository = Repository(json: repositoryBody)
completion(response: XcodeServer.CreateRepositoryResponse.Success(repository))
let (result, error): (Repository?, NSError?) = unthrow {
return try Repository(json: repositoryBody)
}
if let error = error {
completion(response: .Error(error))
} else {
completion(response: .Success(result!))
}
}
}

Expand Down
6 changes: 4 additions & 2 deletions XcodeServerSDK/API Routes/XcodeServer+Toolchain.swift
Expand Up @@ -26,8 +26,10 @@ extension XcodeServer {
}

if let body = (body as? NSDictionary)?["results"] as? NSArray {
let toolchains: [Toolchain] = XcodeServerArray(body)
completion(toolchains: toolchains, error: nil)
let (result, error): ([Toolchain]?, NSError?) = unthrow { _ in
return try XcodeServerArray(body)
}
completion(toolchains: result, error: error)
} else {
completion(toolchains: nil, error: Error.withInfo("Wrong body \(body)"))
}
Expand Down
8 changes: 4 additions & 4 deletions XcodeServerSDK/Server Entities/Bot.swift
Expand Up @@ -14,13 +14,13 @@ public class Bot : XcodeServerEntity {
public let configuration: BotConfiguration
public let integrationsCount: Int

public required init(json: NSDictionary) {
public required init(json: NSDictionary) throws {

self.name = json.stringForKey("name")
self.configuration = BotConfiguration(json: json.dictionaryForKey("configuration"))
self.name = try json.stringForKey("name")
self.configuration = try BotConfiguration(json: try json.dictionaryForKey("configuration"))
self.integrationsCount = json.optionalIntForKey("integration_counter") ?? 0

super.init(json: json)
try super.init(json: json)
}

/**
Expand Down

0 comments on commit be980ce

Please sign in to comment.