`swift run` Server Error

Running swift run in the 00-book-server directory produces the following error on my machine:

./Modern_Concurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:66:91: error: cannot find type 'Task' in scope
    public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
                                                                                          ^~~~
./Modern_Concurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:25:26: error: cannot find 'withUnsafeThrowingContinuation' in scope
        return try await withUnsafeThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./Modern_Concurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:43:26: error: cannot find 'withCheckedThrowingContinuation' in scope
        return try await withCheckedThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[7/8] Compiling NIOCore AsyncAwaitSupport+OldXcodes.swift
error: fatalError

My machine is running Big Sur and I’m using Xcode 13.0.

Looks like an issue in SwiftNIO, I’ll check later today what I get - I also have BigSur on my machine :+1:t3:

1 Like

@icanzilb find anything for this issue?

I get a different error, they must’ve updated Vapor since we published the book. In the worst case we’ll fix Vapor to some older version.

Meanwhile, could you please try this:

  1. cd into the server folder
  2. rm -Rf .build to clean all old checkouts
  3. rm Package.resolved to make sure versions aren’t pinned
  4. swift run
1 Like

I found a solution on the swift forums - while the Apple team is working on properly backporting the Swift Concurrency module you need to run the server as:

swift run --configuration debug -Xlinker -rpath -Xlinker "$(xcode-select -p)/Toolchains/XcodeDefault.xctoolchain/usr/lib/swift-5.5/macosx"

So it can find the Concurrency module inside the default macOS SDK

1 Like

@icanzilb Is there an update on this issue?
I am seeing the same errors posted above and I am running Monterey and Xcode 13.0. I also tried the solutions in the comments and that did not work as well. Thanks!

Can you describe what do you do and what error do you get?

I run swift run or the command from your comment:

in the 00-book-server directory and get

./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:66:91: error: cannot find type 'Task' in scope
    public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
                                                                                          ^~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:25:26: error: cannot find 'withUnsafeThrowingContinuation' in scope
        return try await withUnsafeThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:43:26: error: cannot find 'withCheckedThrowingContinuation' in scope
        return try await withCheckedThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[862/863] Compiling NIOCore AsyncAwaitSupport+OldXcodes.swift
error: fatalError

Could you please make sure you followed the steps I listed above - including cleaning the build directory and deleting the package lock file?

If you still get the same error, please let me know what’s the output of swift --version so I can try to reproduce

Yep, I tried the cleaning steps as well, and here are the errors after the steps listed above:

./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:66:91: error: cannot find type 'Task' in scope
    public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
                                                                                          ^~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:25:26: error: cannot find 'withUnsafeThrowingContinuation' in scope
        return try await withUnsafeThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:43:26: error: cannot find 'withCheckedThrowingContinuation' in scope
        return try await withCheckedThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:66:91: error: cannot find type 'Task' in scope
    public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
                                                                                          ^~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:25:26: error: cannot find 'withUnsafeThrowingContinuation' in scope
        return try await withUnsafeThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:43:26: error: cannot find 'withCheckedThrowingContinuation' in scope
        return try await withCheckedThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:66:91: error: cannot find type 'Task' in scope
    public func completeWithTask(_ body: @escaping @Sendable () async throws -> Value) -> Task<Void, Never> {
                                                                                          ^~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:25:26: error: cannot find 'withUnsafeThrowingContinuation' in scope
        return try await withUnsafeThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
./ModernSwiftConcurrency/00-book-server/.build/checkouts/swift-nio/Sources/NIOCore/AsyncAwaitSupport+OldXcodes.swift:43:26: error: cannot find 'withCheckedThrowingContinuation' in scope
        return try await withCheckedThrowingContinuation { cont in
                         ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
[1043/1044] Compiling NIOCore ByteBuffer-lengthPrefix.swift
error: fatalError

The output of swift --version:

swift-driver version: 1.26.9 Apple Swift version 5.5 (swiftlang-1300.0.31.1 clang-1300.0.29.1)
Target: x86_64-apple-macosx12.0

I’m a little confused myself to be honest, since you have macOS 12 SwiftNIO should be compiling just fine…

What I notice is that the backwards compatibility of the Concurrency module was introduced in Swift 5.5.2 and you have 5.5 so that might be hitting some edge case in the conditional compilations in SwiftNIO.

Have you tried installing the latest Xcode?

So yes I installed the latest Xcode but my command-line tools were pointing to Xcode 13.0, not Xcode 13.2.1, and changing that fixed it for me. Changed it under Xcode → Preferences → Locations. Thanks for your help!

you’re welcome, this really ought to be an issue on NIO’s side where an if isn’t checking for 5.5.2 but 5.5 :man_shrugging:t4:

I am getting this error when trying to run swift run:

Merging module COperatingSystemerror: error reading dependency file ‘/Users/NN/Desktop/Async:Await/ray async:await/00-book-server/.build/x86_64-apple-macosx/debug/COperatingSystem.build/Exports.d’: unexpected character in prerequisites

I have Xcode 13.1 and running macOS Monterey 12.2.1

I’m gonna go on a limb here and guess that the error message saying “unexpected character in prerequisites” is about those colons in the folder names. Can you check out the repo is a folder with a simpler name like “swiftconcurrrency” and try again?

I had a “fatal error: could not build module ‘Darwin’ book server” error.

This set of commands resolved my error.

Cheers!

1 Like

This error means there is a problem on the server side. A server error can be caused by any number of things from uploading the incorrect file to as bug in a piece of code. This error response is a generic “catch-all” response.

Tips to Fix the Server Error
Backing Up Your Site
Clear your browser cookies and cache
Reload or Refresh the Webpage

Greeting,
Rachel Gomez

I had a lot of errors:

/Users/alex/Desktop/concurrency_files/00-book-server/.build/checkouts/vapor/Sources/Vapor/HTTP/Headers/HTTPHeaders+Directive.swift:230:14: error: ambiguous use of ‘split(separator:maxSplits:omittingEmptySubsequences:)’
self.lazy.split(separator: “\”).reduce(into: “”) { (result, part) in
^
Swift.Sequence:2:40: note: found this candidate
@inlinable public __consuming func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) → [ArraySlice<Self.Element>]
^
Swift.Collection:2:40: note: found this candidate
@inlinable public __consuming func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) → [Self.SubSequence]
^
/Users/alex/Desktop/concurrency_files/00-book-server/.build/checkouts/vapor/Sources/Vapor/HTTP/Headers/HTTPHeaders+Directive.swift:230:14: error: ambiguous use of ‘split(separator:maxSplits:omittingEmptySubsequences:)’
self.lazy.split(separator: “\”).reduce(into: “”) { (result, part) in
^
Swift.Sequence:2:40: note: found this candidate
@inlinable public __consuming func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) → [ArraySlice<Self.Element>]
^
Swift.Collection:2:40: note: found this candidate
@inlinable public __consuming func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) → [Self.SubSequence]
^
/Users/alex/Desktop/concurrency_files/00-book-server/.build/checkouts/vapor/Sources/Vapor/HTTP/Headers/HTTPHeaders+Directive.swift:230:14: error: ambiguous use of ‘split(separator:maxSplits:omittingEmptySubsequences:)’
self.lazy.split(separator: “\”).reduce(into: “”) { (result, part) in
^
Swift.Sequence:2:40: note: found this candidate
@inlinable public __consuming func split(separator: Self.Element, maxSplits: Int = Int.max, omittingEmptySubsequences: Bool = true) → [ArraySlice<Self.Element>]
^
Swift.Collection:2:40: note: found this candidate

and so on

XCode Version 14.0.1 (14A400),
swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: x86_64-apple-macosx12.0

I’m running macOS 13 with Xcode 14.1 here and the server builds and runs for me. Can you make sure you have an up to date version of the code from GitHub - kodecocodes/mcon-materials: The projects and materials that accompany the Modern Concurrency in Swift book please?

1 Like

I downloaded latest version of the code from Github and “Yes”. It’s perfectly working.

Thanks for help. :grinning: :+1: :+1: :+1: :heart: :heart: :heart:

1 Like