Skip to content

🐛 Bug Report: Replace unwrap() calls with proper error handling in Client #1397

@yashksaini-coder

Description

@yashksaini-coder

👟 Reproduction steps

In the main src/client.rs file, the Client::new() constructor and setter methods use .parse().unwrap() for header values and .expect() for HTTP client construction:

In Client::new() (lines 91-96):

headers.insert("X-Appwrite-Response-Format", "1.9.0".parse().unwrap());
headers.insert("user-agent", format!("AppwriteRustSDK/0.1.0 ...").parse().unwrap());
headers.insert("x-sdk-name", "Rust".parse().unwrap());
headers.insert("x-sdk-platform", "server".parse().unwrap());
headers.insert("x-sdk-language", "rust".parse().unwrap());
headers.insert("x-sdk-version", "0.1.0".parse().unwrap());

👍 Expected behavior

  • Header values from constant strings in new() are safe and could use // SAFETY: comments to document why unwrap() is acceptable, or be converted to compile-time constants.
  • Header values from user input in set_project(), set_key(), set_jwt(), set_locale(), and set_session() should return Result<Self, AppwriteError> instead of panicking, since user-provided strings can contain invalid header characters (newlines, non-visible ASCII, etc.).
  • set_endpoint() already validates with panic! — it should also return Result.

👎 Actual Behavior

If a user passes a string with invalid header characters (e.g., client.set_key("my\nkey")), the SDK panics at runtime instead of returning an error.

🎲 Appwrite version

Version 0.10.x

💻 Operating system

Linux

🧱 Your Environment

No response

👀 Have you spent some time to check if this issue has been raised before?

  • I checked and didn't find similar issue

🏢 Have you read the Code of Conduct?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions