UNPKG

codebridge-ai

Version:

Complete fullstack AI coding platform with AST-based code integration and local LLM support. Now with comprehensive web technology support (HTML/CSS/JS) plus JavaScript, Python, Rust, and C++.

22 lines 1.31 kB
{ "timestamp": "2025-08-02T16:16:00.759Z", "model": "deepseek-coder:6.7b", "language": "rust", "scenario": "error-handling", "task": "Replace unwrap with proper error handling using Result", "originalCode": "fn read_number(s: &str) -> i32 {\n s.parse().unwrap()\n}", "rawResponse": "Here's how you can improve your function to handle errors properly in Rust:\n\n```rust\nfn read_number(s: &str) -> Result<i32, <ParseError as FromStr>::Err> {\n s.parse().map_err(|e| e.to_string())\n}\n```\n\nIn this version of the function, `parse()` returns a `Result` that can be either an integer (on success) or an error (if parsing fails). The `unwrap()` method is replaced with the `map_err(|e| e.to_string())` which will convert any parse errors into strings for better error handling. This function now returns a `Result` that can either be an integer on success, or an error message if parsing fails.\n", "improvedCode": "fn read_number(s: &str) -> Result<i32, <ParseError as FromStr>::Err> {\n s.parse().map_err(|e| e.to_string())\n}", "duration": 4512, "success": true, "qualityMetrics": { "hasCode": true, "hasResultType": true, "hasBorrowing": true, "taskCompleted": true, "score": 0.7692307692307692, "rawScore": 1, "maxScore": 1.3 }, "error": null }