Skip to content

fix: handle missing filename in file upload to prevent panic#138

Merged
TheWaWaR merged 7 commits into
TheWaWaR:masterfrom
yuancjun:patch-1
Aug 3, 2025
Merged

fix: handle missing filename in file upload to prevent panic#138
TheWaWaR merged 7 commits into
TheWaWaR:masterfrom
yuancjun:patch-1

Conversation

@yuancjun

@yuancjun yuancjun commented Aug 2, 2025

Copy link
Copy Markdown
Contributor

Replace unwrap() calls with proper error handling when processing uploaded files.
When no filename is provided, the server now logs a warning and continues
processing instead of panicking.

🤖 Generated with Claude Code

Co-Authored-By: Claude noreply@anthropic.com

2025-08-02-upload.txt

  Replace unwrap() calls with proper error handling when processing uploaded files.
  When no filename is provided, the server now logs a warning and continues
  processing instead of panicking.

  🤖 Generated with [Claude Code](https://claude.ai/code)

  Co-Authored-By: Claude <noreply@anthropic.com>
Comment thread src/main.rs
println!("[Warning]: Invalid filename: {}", raw_filename);
continue;
}
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please use if-let-else here.

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

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

@TheWaWaR

  • Use if-let-else pattern for both filename extraction and validation ✅

@TheWaWaR TheWaWaR Aug 2, 2025

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

let Some(raw_filename) = headers.filename.clone() else {
    println!("[Warning]: Skipping field with no filename");
    continue;
};

Copy link
Copy Markdown
Owner

Choose a reason for hiding this comment

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

Please run cargo fmt for your code.

@yuancjun

yuancjun commented Aug 2, 2025

Copy link
Copy Markdown
Contributor Author
Screenshot 2025-08-02 at 4 03 39 PM

  - Replace unwrap() calls with proper error handling when processing uploaded files
  - Use if-let pattern for filename validation as requested
  - When no filename is provided, server now logs warning and continues instead of panicking

  🤖 Generated with [Claude Code](https://claude.ai/code)

  Co-Authored-By: Claude <noreply@anthropic.com>
  - Replace unwrap() calls with proper error handling when processing uploaded files
  - Use if-let-else pattern for both filename extraction and validation
  - When no filename is provided, server now logs warning and continues instead of panicking

  🤖 Generated with [Claude Code](https://claude.ai/code)

  Co-Authored-By: Claude <noreply@anthropic.com>
  - Replace unwrap() calls with proper error handling when processing uploaded files
  - Use if-let-else pattern for both filename extraction and validation
  - When no filename is provided, server now logs warning and continues instead of panicking

  🤖 Generated with [Claude Code](https://claude.ai/code)

  Co-Authored-By: Claude <noreply@anthropic.com>
- Replace unsafe unwrap() calls with safe if-let-else pattern
  - Add proper validation for missing and invalid filenames
  - Skip malformed uploads with warning messages instead of panicking
  - Use modern Rust idioms for cleaner error handling

  Addresses potential crashes when users upload files without proper
  filename headers or with invalid path names.
  - Replace unsafe unwrap() calls with safe if-let-else pattern
  - Add proper validation for missing and invalid filenames
  - Skip malformed uploads with warning messages instead of panicking
  - Use modern Rust idioms for cleaner error handling

  Addresses potential crashes when users upload files without proper
  filename headers or with invalid path names.
@TheWaWaR TheWaWaR merged commit 4beb0fc into TheWaWaR:master Aug 3, 2025
11 checks passed
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

Successfully merging this pull request may close these issues.

2 participants