Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Crash with custom Decodable property that is not a command line option #683

Open
2 tasks done
Jomy10 opened this issue Nov 13, 2024 · 0 comments
Open
2 tasks done

Comments

@Jomy10
Copy link

Jomy10 commented Nov 13, 2024

When a property in a ParsableCommand has a custom Decodable implementation, but it is not a Flag, Option or Argument, and the custom decodable implementation uses nestedContainer, the program will crash.

The crash is the following:

ArgumentParser/ArgumentDecoder.swift:135: Fatal error
[1]    77018 illegal hardware instruction  [executable path] --help

ArgumentParser version: 1.5.0
Swift version: Paste the output of swift --version here.

swift-driver version: 1.62.15 Apple Swift version 5.7.2 (swiftlang-5.7.2.135.5 clang-1400.0.29.51)
Target: x86_64-apple-macosx13.0

Checklist

  • If possible, I've reproduced the issue using the main branch of this package
  • I've searched for existing GitHub issues

Steps to Reproduce

@main
struct Main: ParsableCommand {
  var property: MyCustomDecodableStruct = MyCustomDecodableStruct()
}

struct MyCustomDecodableStruct: Decodable {
  enum CodingKeys: String, CodingKey {
    case input
    case output
  }
  enum InputCodingKeys: String, CodingKey {
    case inputLanguage = "language"
  }

  enum OutputCodingKeys: String, CodingKey {
    case outputLanguage = "language"
  }

  init(from decoder: Decoder) throws {
    let container = try decoder.container(keyedBy: CodingKeys.self)
    let input = try container.nestedContainer(keyedBy: InputCodingKeys.self, forKey: .input)
    let output = try container.nestedContainer(keyedBy: OutputCodingKeys.self, forKey: .output)

    /* rest of the implementation */
  }
}

Expected behavior

This property should be ignored

Actual behavior

ArgumentParser/ArgumentDecoder.swift:135: Fatal error
[1]    77018 illegal hardware instruction  [executable path] --help

Sidenote

Important to note is that on Swift 5.7, this will cause the compiler to crash in debug mode, but not in release mode

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant