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

EXC_BREAKPOINT crash when using ReplaceError parser #328

Open
russellyeo opened this issue Dec 3, 2023 · 2 comments
Open

EXC_BREAKPOINT crash when using ReplaceError parser #328

russellyeo opened this issue Dec 3, 2023 · 2 comments

Comments

@russellyeo
Copy link

I have encountered a crash when using replaceError(with:), and can reproduce it using the example documented in the OneOf parser.

enum Currency { case eur, gbp, usd, unknown }

let currency = OneOf {
    "".map { Currency.eur }
    "£".map { Currency.gbp }
    "$".map { Currency.usd }
}
.replaceError(with: Currency.unknown)

print(currency.parse("$")) // Currency.usd
print(currency.parse("฿")) // Thread 1: EXC_BREAKPOINT (code=1, subcode=0x100004650)

Using a SPM executable package on Xcode 15.0.1 (15A507)

I tried stepping through the library code to try see if I could find the root cause, but I think it is beyond my ability/understanding!

Thanks,
Russell

@griffrawk
Copy link

Xcode 16.1 and swift-parsing 0.13.0

Also receiving the same error in the same example. I was testing using the example because I was getting something strange in my own code where .replaceError appeared to do nothing. I thought if the example was Ok, then it was something I'm doing wrong, but now I'm not sure...

func oneOfExample() {
    enum Currency { case eur, gbp, usd, unknown }

    let currency = OneOf {
      "".map { Currency.eur }
      "£".map { Currency.gbp }
      "$".map { Currency.usd }
    }
    .replaceError(with: Currency.unknown)

    print(currency.parse("$"))  // Currency.usd
    print(currency.parse("฿"))  // Currency.unknown Thread 1: EXC_BREAKPOINT (code=1, subcode=0x103370d74)
}

@mbrandonw
Copy link
Member

Hi @griffrawk & @russellyeo, this unfortunately seems to be a Swift compiler bug in @rethrows. That is a mechanism to allow one to have throwing requirements in protocols such that if a conformance does not actually throw then you don't need try. That is why you don't have to try the .parse even though typically parsing is a failable operation.

This may be reason enough to remove @rethrows from the library, which we can do someday (or if someone wants to PR it!), but in the meantime you could also just copy-paste ReplaceError into your own project and add a throws to the parse. That alone will fix the issue.

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

3 participants