sweepai-dev / firezone

WireGuardยฎ-based VPN server and firewall
https://firezone.dev
Apache License 2.0
0 stars 0 forks source link

Sweep: Improve `SwiftConnlibError` #1

Open wwzeng1 opened 1 year ago

wwzeng1 commented 1 year ago

Right now swift-bridge supports enums with associated data, like so:

// Rust
#[swift_bridge::bridge]
mod ffi {
    enum SwiftConnlibError {
        Io { description: String, value: usize}, //support struct 
        Base64DecodeError(u32, String), //support tuple
        Base64DecodeSliceError
        //..
    }
// Swift
switch swiftConnlibError {
    case .Io(let description, let value):
       //..
    case .Base64DecodeError(let value):
      //..
}

So, we can provide users with more error information by introducing this feature.

sweep-ai[bot] commented 1 year ago

Here's the PR! https://github.com/sweepai-dev/firezone/pull/3.

๐Ÿ’Ž Sweep Pro: I used GPT-4 to create this ticket. You have 5 GPT-4 tickets left.


Step 1: ๐Ÿ” Code Search

I found the following snippets in your repository. I will now analyze these snippets and come up with a plan.

Some code snippets I looked at (click to expand). If some file is missing from here, you can mention the path in the ticket description. https://github.com/sweepai-dev/firezone/blob/1c93c376ceac95395925ab10aef18709b39bc243/rust/connlib/clients/apple/src/lib.rs#L1-L162 https://github.com/sweepai-dev/firezone/blob/1c93c376ceac95395925ab10aef18709b39bc243/swift/apple/Firezone.xcodeproj/project.pbxproj#L69-L147 https://github.com/sweepai-dev/firezone/blob/1c93c376ceac95395925ab10aef18709b39bc243/rust/connlib/libs/common/src/error.rs#L1-L79 https://github.com/sweepai-dev/firezone/blob/1c93c376ceac95395925ab10aef18709b39bc243/rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift#L1-L71

Step 2: ๐Ÿง Snippet Analysis

From looking through the relevant snippets, I decided to make the following modifications:

File Path Proposed Changes
rust/connlib/clients/apple/src/lib.rs Update the SwiftConnlibError enum to include associated data for each variant. For example, the Io variant could be updated to Io { description: String, value: usize }, and similarly for the other variants.
rust/connlib/clients/apple/Sources/Connlib/CallbackHandler.swift Update the switch cases in the onDisconnect and onError functions to handle the new associated data in the SwiftConnlibError enum. For example, the case for .Io could be updated to .Io(let description, let value).

Step 3: ๐Ÿ“ Planning

I have created a plan for writing the pull request. I am now working my plan and coding the required changes to address this issue. Here is the planned pull request:

Improve SwiftConnlibError sweep/improve-swiftconnliberror

Description

This PR improves the SwiftConnlibError enum in the Rust code to include associated data for each variant. This allows for more detailed error information to be provided to the Swift side. The associated data can be a combination of string descriptions and numerical values that provide context about the error.

Changes Made

  • Updated the SwiftConnlibError enum in the Rust code to include associated data for each variant.
  • Updated the switch cases in the onDisconnect and onError functions in the Swift code to handle the new associated data in the SwiftConnlibError enum.

Related Issue

Issue #1

Checklist

  • [ ] Updated the SwiftConnlibError enum in the Rust code.
  • [ ] Updated the switch cases in the onDisconnect and onError functions in the Swift code.
  • [ ] Added appropriate tests.
  • [ ] Updated the documentation.
  • [ ] Ran the test suite and ensured all tests pass.
  • [ ] Verified that the changes work as expected.

Additional Notes

None


Step 4: โŒจ๏ธ Coding

I have finished coding the issue. I am now reviewing it for completeness.


Step 5: ๐Ÿ” Code Review

Success! ๐Ÿš€


I'm a bot that handles simple bugs and feature requests but I might make mistakes. Please be kind! Join Our Discord