diff --git a/Sources/SWBBuildService/BuildService.swift b/Sources/SWBBuildService/BuildService.swift index e1219955..1353d736 100644 --- a/Sources/SWBBuildService/BuildService.swift +++ b/Sources/SWBBuildService/BuildService.swift @@ -90,20 +90,24 @@ open class BuildService: Service, @unchecked Sendable { let fs = SWBUtil.localFS var binariesToCheck = [Path]() // Check our own bundle's executable. - if let executablePath = try Bundle.main.executableURL?.filePath { - if fs.exists(executablePath) { - binariesToCheck.append(executablePath) + do { + if let executablePath = try Bundle.main.executableURL?.filePath { + if fs.exists(executablePath) { + binariesToCheck.append(executablePath) + } } + } catch { + throw StubError.error("Couldn't get main bundle executable URL. Error: \(error), bundle: \(Bundle.main), url: \(String(describing: Bundle.main.executableURL)), path: \(String(describing: try? Bundle.main.executableURL?.filePath))") } // Check all the binaries of frameworks in the Frameworks folder. // Note that this does not recurse into the frameworks for other items nested inside them. We also presently don't check the PlugIns folder. - if let frameworksPath = try Bundle.main.privateFrameworksURL?.filePath { + if let frameworksPath = try? Bundle.main.privateFrameworksURL?.filePath { do { for subpath in try fs.listdir(frameworksPath) { let frameworkPath = frameworksPath.join(subpath) // Load a bundle at this path. This means we'll skip things which aren't bundles, such as the Swift standard libraries. if let bundle = Bundle(path: frameworkPath.str) { - if let unresolvedExecutablePath = try bundle.executableURL?.filePath { + if let unresolvedExecutablePath = try? bundle.executableURL?.filePath { let executablePath = try fs.realpath(unresolvedExecutablePath) if fs.exists(executablePath) { binariesToCheck.append(executablePath) diff --git a/Sources/SWBUtil/URL.swift b/Sources/SWBUtil/URL.swift index 264a792d..595afba2 100644 --- a/Sources/SWBUtil/URL.swift +++ b/Sources/SWBUtil/URL.swift @@ -28,7 +28,9 @@ extension URL { throw FileURLError.notRepresentable(self) } let fp = Path(String(cString: cString)) - precondition(fp.isAbsolute, "path '\(fp.str)' is not absolute") + guard fp.isAbsolute else { + throw FileURLError.pathNotAbsolute(fp) + } return fp } } @@ -37,4 +39,5 @@ extension URL { fileprivate enum FileURLError: Error { case notRepresentable(URL) + case pathNotAbsolute(Path) }