Skip to content

Remove useless try to fix warnings#412

Merged
Lukasa merged 2 commits intoapple:mainfrom
ptoffy:fix-throwing-warning
Sep 22, 2025
Merged

Remove useless try to fix warnings#412
Lukasa merged 2 commits intoapple:mainfrom
ptoffy:fix-throwing-warning

Conversation

@ptoffy
Copy link
Contributor

@ptoffy ptoffy commented Sep 17, 2025

getKeyPrimitives is marked as throws but is not actually throwing errors and this is yielding warnings. This fixes the warnings.

Checklist

  • I've run tests to see all new and existing tests pass
  • I've followed the code style of the rest of the project
  • I've read the Contribution Guidelines
  • I've updated the documentation if necessary

If you've made changes to gyb files

  • [N/A] I've run ./scripts/generate_boilerplate_files_with_gyb.sh and included updated generated files in a commit of this pull request

Motivation:

Currently there's a warning

/swift-crypto/Sources/_CryptoExtras/RSA/RSA_boring.swift:67:9: warning: no calls to throwing functions occur within 'try' expression

because we're using try on a non throwing function. This escalates to all of the functions that use it.
I'm not sure if removing throws from a non-actually-throwing public function is breaking, as using try on a non throwing function only yields a warning (if not in warnings-as-errors mode) but it actively is a signature change so it might still be breaking. In case we don't want to merge this as is, the warning can be removed by simply removing useless trys and we can wait for the next major version to remove the false-throwers.

Modifications:

Remove the useless try and throws where they're not needed.

Result:

The warning is gone.

@Lukasa Lukasa added the 🔨 semver/patch No public API change. label Sep 19, 2025

public func getKeyPrimitives() throws -> Primitives {
let (n, e) = try self.backing.getKeyPrimitives()
public func getKeyPrimitives() -> Primitives {
Copy link
Contributor

Choose a reason for hiding this comment

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

Let's leave the throws on the public functions and just remove the incorrect internal trys.

@ptoffy ptoffy changed the title Remove useless throws to fix warnings Remove useless try to fix warnings Sep 22, 2025
@ptoffy ptoffy requested a review from Lukasa September 22, 2025 07:40
@Lukasa
Copy link
Contributor

Lukasa commented Sep 22, 2025

Thanks @ptoffy!

@Lukasa Lukasa enabled auto-merge (squash) September 22, 2025 10:57
@Lukasa Lukasa merged commit 527fef6 into apple:main Sep 22, 2025
45 of 46 checks passed
@ptoffy ptoffy deleted the fix-throwing-warning branch September 22, 2025 14:08
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

🔨 semver/patch No public API change.

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants