apple / apple/swift-argument-parser
Unexpected “Asynchronous subcommand of a synchronous root”
- Dominant language
- Swift
- Stars
- 3.8k
- Forks
- 411
- Avg merge
- 7d 13h
- Merged PRs (30d)
- 17
Description
When attempting to create an application with a AsyncParsableCommand root and AsyncParsableCommand subcommands, a fatal error is thrown at runtime “Asynchronous subcommand of a synchronous root.”
**ArgumentParser version:** `1.2.0`
**Swift version:** `swift-driver version: 1.62.8 Apple Swift version 5.7 (swiftlang-5.7.0.127.4 clang-1400.0.29.50)
Target: arm64-apple-macosx13.0`
### Checklist
- [ ] If possible, I've reproduced the issue using the `main` branch of this package
- [x] I've searched for [existing GitHub issues](https://github.com/apple/swift-argument-parser/issues)
### Steps to Reproduce
source:
```
import protocol ArgumentParser.AsyncParsableCommand
import struct ArgumentParser.CommandConfiguration
@main
struct asyncissue: AsyncParsableCommand {
static var configuration = CommandConfiguration(subcommands: [Cmd1.self])
struct Cmd1: AsyncParsableCommand {
mutating func run() async throws {
print("Hello")
}
}
}
```
### Expected behavior
When resulting command is run, help with a subcommand would be displayed.
### Actual behavior
```
ArgumentParser/ParsableCommand.swift:184: Fatal error:
--------------------------------------------------------------------
Asynchronous subcommand of a synchronous root.
The asynchronous command `Cmd1` is declared as a subcommand of the
synchronous root command `asyncissue`.
With this configuration, your asynchronous `run()` method will not be
called. To fix this issue, change `asyncissue`'s `ParsableCommand`
conformance to `AsyncParsableCommand`.
--------------------------------------------------------------------
zsh: trace trap swift run
```
Contributor guide
Research direction
Reproduce the sample application with Swift ArgumentParser 1.2.0, then inspect ParsableCommand.swift around line 184 where the fatal error is reported. Verify the root and subcommand conformances used by the sample; done means the asynchronous root and subcommand run without the synchronous-root fatal error and display help as expected.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- swift
- Domain
- cli
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Stale
- Clarity
- Clearly specified
- Newbie friendliness
- 45/100