Skip to content

Commit aa08360

Browse files
committed
Fix fatal crash caused by force unwrap
1 parent 349f14d commit aa08360

File tree

5 files changed

+50
-5
lines changed

5 files changed

+50
-5
lines changed

Package.resolved

Lines changed: 18 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

Package.swift

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,13 +9,15 @@ let package = Package(
99
dependencies: [
1010
.package(url: "https://github.com/apple/swift-argument-parser", from: "1.0.0"),
1111
.package(name: "DeltaLogger", url: "https://github.com/stackotter/delta-logger", .branch("main")),
12+
.package(url: "https://github.com/norio-nomura/SwiftBacktrace", from: "1.0.1"),
1213
],
1314
targets: [
1415
.target(
1516
name: "swift-bundler",
1617
dependencies: [
1718
.product(name: "ArgumentParser", package: "swift-argument-parser"),
1819
"DeltaLogger",
20+
"SwiftBacktrace"
1921
]),
2022
]
2123
)

Sources/swift-bundler/Subcommands/Build.swift

Lines changed: 9 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -89,8 +89,14 @@ extension Bundler {
8989
} else if line.starts(with: "[") {
9090
let parts = line.split(separator: "]")
9191
let progressParts = parts[0].dropFirst().split(separator: "/")
92-
let progress = Double(progressParts[0])!
93-
let total = Double(progressParts[1])!
92+
93+
guard
94+
let progress = Double(progressParts[0]),
95+
let total = Double(progressParts[1])
96+
else {
97+
return
98+
}
99+
94100
let decimalProgress = progress / total
95101
updateProgress(line, 0.8 * decimalProgress + 0.1, shouldLog: false)
96102
} else if line.starts(with: "Fetching") || line.starts(with: "Resolving") || line.starts(with: "Cloning") {
@@ -128,4 +134,4 @@ extension Bundler {
128134

129135
updateProgress("Build completed", 1)
130136
}
131-
}
137+
}

Sources/swift-bundler/main.swift

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,23 @@
1+
import Foundation
2+
import SwiftBacktrace
3+
4+
NSSetUncaughtExceptionHandler { (exception) in
5+
let stack = exception.callStackReturnAddresses
6+
print("Stack trace: \(stack)")
7+
}
8+
9+
func handleSignal(_ code: Int32) {
10+
print("caught crash")
11+
}
12+
13+
signal(SIGABRT, handleSignal);
14+
signal(SIGILL, handleSignal);
15+
signal(SIGSEGV, handleSignal);
16+
signal(SIGFPE, handleSignal);
17+
signal(SIGBUS, handleSignal);
18+
signal(SIGPIPE, handleSignal);
19+
120
Bundler.main()
221

322
// TODO: support sandboxing
4-
// TODO: add proper help messages to subcommands, options and flags
23+
// TODO: add proper help messages to subcommands, options and flags

install.sh

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
#!/bin/sh
22
# Build
3-
swift build -c release
3+
swift build -c debug
44

55
# Create directory with correct permissions
66
sudo mkdir -p -m755 /opt/swift-bundler

0 commit comments

Comments
 (0)