Skip to content

Conversation

d-ronnqvist
Copy link
Contributor

Bug/issue #, if applicable:

Summary

This PR adopts SE-0413 where possible to provide callers with more information about possible raised errors.

  • ac7eeae updates code where the caller knew the only possible errors were raised but needed a redundant catch block to satisfy the compiler:

    do {
        try doSomething()
    } catch let error as KnownError {
        // ...
    } catch {
       fatalError("`doSomething()` only throws `KnownError`")
    }

    By providing the compiler with information about the errors that doSomething() can raise, the compiler can verify that the implementation doesn't unintentionally raise any other errors and the default catch block provides an error value of the right type:

    do {
        try doSomething()
    } catch {
        // `error` is already bound to a `KnownError` value here
    }
  • e8465bc updates a few additional methods that only raise a single type of error to provide this information to the caller, even if there's no callers to update.

  • ac7eeae updates some of our helper methods to use throws(E) instead of rethrows so that typed error information isn't lost when using these helpers.

Dependencies

None.

Testing

Nothing in particular. This isn't a user-facing change.

Checklist

Make sure you check off the following items. If they cannot be completed, provide a reason.

  • Added Updated tests
  • Ran the ./bin/test script and it succeeded
  • [ ] Updated documentation if necessary

@d-ronnqvist d-ronnqvist added the code cleanup Code cleanup *without* user facing changes label Sep 24, 2025
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@heckj heckj self-requested a review September 26, 2025 16:18
Copy link
Member

@heckj heckj left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice example of using typed errors

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

1 similar comment
@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist
Copy link
Contributor Author

The CI issue will be resolved by #1308

@d-ronnqvist
Copy link
Contributor Author

@swift-ci please test

@d-ronnqvist d-ronnqvist merged commit cf6dde1 into swiftlang:main Sep 29, 2025
2 checks passed
@d-ronnqvist d-ronnqvist deleted the typed-throws branch September 29, 2025 16:13
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
code cleanup Code cleanup *without* user facing changes
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants