[{"data":1,"prerenderedAt":-1},["ShallowReactive",2],{"skill:01M6ETKM8ZMHFQ6TJ3WTM7P9AM":3,"skill-same:01M6ETKM8ZMHFQ6TJ3WTM7P9AM":67},{"skillNo":4,"name":5,"nameZh":6,"description":7,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":16,"categories":17,"keywords":18,"publishedAt":31,"linkOnly":32,"markdownContent":33,"markdownBody":34,"frontMatter":35,"refName":38,"commitSha":39,"skillDirectory":40,"forksCount":41,"repositoryHtmlUrl":42,"repositoryHomepageUrl":43,"ownerHtmlUrl":44,"ownerBlogUrl":6,"ownerDescription":45,"updatedAt":46,"install":47,"resources":60},"01M6ETKM8ZMHFQ6TJ3WTM7P9AM","error-conversion-guide",null,"Guides users on error conversion patterns, From trait implementations, and the ? operator. Activates when users need to convert between error types or handle multiple error types in a function.","ComeOnOliver\u002Fskillshub","ComeOnOliver","https:\u002F\u002Favatars.githubusercontent.com\u002Fu\u002F43215937?v=4","01M6E5JNFECJAAVFE0W7SMWWD2","Haoran Shu","01M6E5JNNDQS7AJZDYFQ8TPZCK",67,"MIT","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Femillindfors\u002Ferror-conversion-guide\u002FSKILL.md",[],[19,20,21,22,23,24,25,26,27,28,29,30],"guide","conversion","error","error conversion guide","operator","convert","grep","read","patterns","guides","users","types","2026-11-10 10:12:30",false,"---\nname: error-conversion-guide\ndescription: Guides users on error conversion patterns, From trait implementations, and the ? operator. Activates when users need to convert between error types or handle multiple error types in a function.\nallowed-tools: Read, Grep\nversion: 1.0.0\n---\n\n# Error Conversion Guide Skill\n\nYou are an expert at Rust error conversion patterns. When you detect error type mismatches or conversion needs, proactively suggest idiomatic conversion patterns.\n\n## When to Activate\n\nActivate this skill when you notice:\n- Multiple error types in a single function\n- Manual error conversion with `map_err`\n- Type mismatch errors with the `?` operator\n- Questions about From\u002FInto traits for errors\n- Need to combine different error types\n\n## Error Conversion Patterns\n\n### Pattern 1: Automatic Conversion with #[from]\n\n**What to Look For**:\n- Manual `map_err` calls that could be automatic\n- Repetitive error conversions\n\n**Before**:\n```rust\n#[derive(Debug)]\npub enum AppError {\n    Io(std::io::Error),\n    Parse(std::num::ParseIntError),\n}\n\nfn process() -> Result\u003Ci32, AppError> {\n    let content = std::fs::read_to_string(\"data.txt\")\n        .map_err(|e| AppError::Io(e))?;  \u002F\u002F ❌ Manual conversion\n\n    let num = content.trim().parse::\u003Ci32>()\n        .map_err(|e| AppError::Parse(e))?;  \u002F\u002F ❌ Manual conversion\n\n    Ok(num)\n}\n```\n\n**After**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),  \u002F\u002F ✅ Automatic From impl\n\n    #[error(\"Parse error\")]\n    Parse(#[from] std::num::ParseIntError),  \u002F\u002F ✅ Automatic From impl\n}\n\nfn process() -> Result\u003Ci32, AppError> {\n    let content = std::fs::read_to_string(\"data.txt\")?;  \u002F\u002F ✅ Auto-converts\n    let num = content.trim().parse::\u003Ci32>()?;  \u002F\u002F ✅ Auto-converts\n    Ok(num)\n}\n```\n\n**Suggestion Template**:\n```\nUse #[from] in your error enum to enable automatic conversion:\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),\n}\n\nThis implements From\u003Cstd::io::Error> for AppError, allowing ? to automatically convert.\n```\n\n### Pattern 2: Manual From Implementation\n\n**What to Look For**:\n- Custom error types that need conversion\n- Complex conversion logic\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"Database error: {message}\")]\n    Database { message: String },\n\n    #[error(\"Validation error: {0}\")]\n    Validation(String),\n}\n\n\u002F\u002F Manual From for custom conversion logic\nimpl From\u003Csqlx::Error> for AppError {\n    fn from(err: sqlx::Error) -> Self {\n        AppError::Database {\n            message: format!(\"Database operation failed: {}\", err),\n        }\n    }\n}\n\n\u002F\u002F Convert with context\nimpl From\u003Cvalidator::ValidationErrors> for AppError {\n    fn from(err: validator::ValidationErrors) -> Self {\n        let messages: Vec\u003CString> = err\n            .field_errors()\n            .iter()\n            .map(|(field, errors)| {\n                format!(\"{}: {:?}\", field, errors)\n            })\n            .collect();\n\n        AppError::Validation(messages.join(\", \"))\n    }\n}\n```\n\n**Suggestion Template**:\n```\nWhen you need custom conversion logic, implement From manually:\n\nimpl From\u003CSourceError> for AppError {\n    fn from(err: SourceError) -> Self {\n        AppError::Variant {\n            field: extract_info(&err),\n        }\n    }\n}\n```\n\n### Pattern 3: Converting Between Result Types\n\n**What to Look For**:\n- Calling functions with different error types\n- Need to unify error types\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ServiceError {\n    #[error(\"Repository error\")]\n    Repository(#[from] RepositoryError),\n\n    #[error(\"External API error\")]\n    Api(#[from] ApiError),\n\n    #[error(\"Validation error\")]\n    Validation(#[from] ValidationError),\n}\n\n\u002F\u002F All these errors convert automatically\nfn service_operation() -> Result\u003CData, ServiceError> {\n    \u002F\u002F Returns Result\u003C_, RepositoryError>\n    let data = repository.fetch()?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    \u002F\u002F Returns Result\u003C_, ValidationError>\n    validate(&data)?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    \u002F\u002F Returns Result\u003C_, ApiError>\n    let enriched = api_client.enrich(data)?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    Ok(enriched)\n}\n```\n\n**Suggestion Template**:\n```\nCreate a unified error type that can convert from all the errors you need:\n\n#[derive(Error, Debug)]\npub enum UnifiedError {\n    #[error(\"Database error\")]\n    Database(#[from] DbError),\n\n    #[error(\"Network error\")]\n    Network(#[from] NetworkError),\n}\n\nfn operation() -> Result\u003C(), UnifiedError> {\n    db_operation()?;  \u002F\u002F Auto-converts\n    network_operation()?;  \u002F\u002F Auto-converts\n    Ok(())\n}\n```\n\n### Pattern 4: map_err for One-Off Conversions\n\n**What to Look For**:\n- Single conversion that doesn't justify From impl\n- Adding context during conversion\n\n**Pattern**:\n```rust\nuse anyhow::Context;\n\nfn process(id: &str) -> anyhow::Result\u003CData> {\n    \u002F\u002F One-off conversion with context\n    let config = load_config()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load config: {}\", e))?;\n\n    \u002F\u002F Better: use context\n    let config = load_config()\n        .context(\"Failed to load config\")?;\n\n    \u002F\u002F map_err for type conversion without From impl\n    let data = fetch_data(id)\n        .map_err(|e| format!(\"Fetch failed for {}: {}\", id, e))?;\n\n    Ok(data)\n}\n```\n\n**When to Use**:\n- One-off conversions\n- Adding context to specific call sites\n- Converting to types that don't have From impl\n\n**Suggestion Template**:\n```\nFor one-off conversions or adding context, use map_err or anyhow's context:\n\n\u002F\u002F With map_err\noperation().map_err(|e| MyError::Custom(format!(\"Failed: {}\", e)))?;\n\n\u002F\u002F With anyhow (preferred)\noperation().context(\"Operation failed\")?;\n```\n\n### Pattern 5: Error Type Aliases\n\n**What to Look For**:\n- Repetitive Result\u003CT, MyError> types\n- Complex error type signatures\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),\n\n    #[error(\"Parse error\")]\n    Parse(#[from] serde_json::Error),\n}\n\n\u002F\u002F Type alias for cleaner signatures\npub type Result\u003CT> = std::result::Result\u003CT, AppError>;\n\n\u002F\u002F Now use it everywhere\npub fn load_config() -> Result\u003CConfig> {  \u002F\u002F ✅ Clean\n    let bytes = std::fs::read(\"config.json\")?;\n    let config = serde_json::from_slice(&bytes)?;\n    Ok(config)\n}\n\n\u002F\u002F Instead of\npub fn load_config_verbose() -> std::result::Result\u003CConfig, AppError> {  \u002F\u002F ❌ Verbose\n    \u002F\u002F ...\n}\n```\n\n**Suggestion Template**:\n```\nCreate a type alias for your Result type:\n\npub type Result\u003CT> = std::result::Result\u003CT, AppError>;\n\nThen use it in function signatures:\n\npub fn operation() -> Result\u003CData> {\n    Ok(data)\n}\n```\n\n### Pattern 6: Boxing Errors\n\n**What to Look For**:\n- Need for dynamic error types\n- Functions that can return multiple error types\n\n**Pattern**:\n```rust\n\u002F\u002F For libraries that need flexibility\ntype BoxError = Box\u003Cdyn std::error::Error + Send + Sync>;\n\nfn flexible_function() -> Result\u003CData, BoxError> {\n    let data1 = io_operation()?;  \u002F\u002F std::io::Error auto-boxes\n    let data2 = parse_operation()?;  \u002F\u002F ParseError auto-boxes\n    Ok(combine(data1, data2))\n}\n\n\u002F\u002F Or use anyhow for applications\nuse anyhow::Result;\n\nfn application_function() -> Result\u003CData> {\n    let data1 = io_operation()?;\n    let data2 = parse_operation()?;\n    Ok(combine(data1, data2))\n}\n```\n\n**Trade-offs**:\n- ✅ Flexible: Can return any error type\n- ✅ Simple: No need to define custom error enum\n- ❌ Dynamic: Error type not known at compile time\n- ❌ Harder to match on specific errors\n\n**Suggestion Template**:\n```\nFor flexible error handling, use Box\u003Cdyn Error> or anyhow:\n\n\u002F\u002F Libraries: Box\u003Cdyn Error>\ntype BoxError = Box\u003Cdyn std::error::Error + Send + Sync>;\nfn operation() -> Result\u003CT, BoxError> { ... }\n\n\u002F\u002F Applications: anyhow\nuse anyhow::Result;\nfn operation() -> Result\u003CT> { ... }\n```\n\n### Pattern 7: Layered Error Conversion\n\n**What to Look For**:\n- Multi-layer architecture (domain, infra, app)\n- Need for error boundary between layers\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n\u002F\u002F Infrastructure layer\n#[derive(Error, Debug)]\npub enum InfraError {\n    #[error(\"Database error\")]\n    Database(#[from] sqlx::Error),\n\n    #[error(\"HTTP error\")]\n    Http(#[from] reqwest::Error),\n}\n\n\u002F\u002F Domain layer (doesn't know about infrastructure)\n#[derive(Error, Debug)]\npub enum DomainError {\n    #[error(\"User not found: {0}\")]\n    UserNotFound(String),\n\n    #[error(\"Invalid data: {0}\")]\n    InvalidData(String),\n}\n\n\u002F\u002F Application layer unifies both\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"Domain error: {0}\")]\n    Domain(#[from] DomainError),\n\n    #[error(\"Infrastructure error: {0}\")]\n    Infra(#[from] InfraError),\n}\n\n\u002F\u002F Infrastructure to Domain conversion (at boundary)\nimpl From\u003CInfraError> for DomainError {\n    fn from(err: InfraError) -> Self {\n        match err {\n            InfraError::Database(e) if e.to_string().contains(\"not found\") => {\n                DomainError::UserNotFound(\"User not found in database\".to_string())\n            }\n            _ => DomainError::InvalidData(\"Data access failed\".to_string()),\n        }\n    }\n}\n```\n\n**Suggestion Template**:\n```\nFor layered architectures, convert errors at layer boundaries:\n\n\u002F\u002F Infrastructure → Domain conversion\nimpl From\u003CInfraError> for DomainError {\n    fn from(err: InfraError) -> Self {\n        \u002F\u002F Convert infrastructure concepts to domain concepts\n        match err {\n            InfraError::NotFound => DomainError::EntityNotFound,\n            _ => DomainError::InfrastructureFailed,\n        }\n    }\n}\n```\n\n## Advanced Patterns\n\n### Pattern 8: Multiple Error Sources with Custom Logic\n\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ProcessError {\n    #[error(\"Stage 1 failed: {0}\")]\n    Stage1(String),\n\n    #[error(\"Stage 2 failed: {0}\")]\n    Stage2(String),\n}\n\n\u002F\u002F Custom conversion with different variants\nimpl From\u003CStage1Error> for ProcessError {\n    fn from(err: Stage1Error) -> Self {\n        ProcessError::Stage1(err.to_string())\n    }\n}\n\nimpl From\u003CStage2Error> for ProcessError {\n    fn from(err: Stage2Error) -> Self {\n        ProcessError::Stage2(err.to_string())\n    }\n}\n\nfn process() -> Result\u003C(), ProcessError> {\n    stage1()?;  \u002F\u002F Converts to ProcessError::Stage1\n    stage2()?;  \u002F\u002F Converts to ProcessError::Stage2\n    Ok(())\n}\n```\n\n### Pattern 9: Fallible Conversion\n\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ConversionError {\n    #[error(\"Incompatible error type: {0}\")]\n    Incompatible(String),\n}\n\n\u002F\u002F TryFrom for fallible conversion\nimpl TryFrom\u003CExternalError> for MyError {\n    type Error = ConversionError;\n\n    fn try_from(err: ExternalError) -> Result\u003CSelf, Self::Error> {\n        match err.code() {\n            404 => Ok(MyError::NotFound),\n            500 => Ok(MyError::Internal),\n            _ => Err(ConversionError::Incompatible(\n                format!(\"Unknown error code: {}\", err.code())\n            )),\n        }\n    }\n}\n```\n\n## Common Mistakes\n\n### Mistake 1: Multiple #[from] for Same Type\n\n```rust\n\u002F\u002F ❌ BAD: Can't have two #[from] for same type\n#[derive(Error, Debug)]\npub enum MyError {\n    #[error(\"First\")]\n    First(#[from] std::io::Error),\n\n    #[error(\"Second\")]\n    Second(#[from] std::io::Error),  \u002F\u002F ❌ Conflict!\n}\n\n\u002F\u002F ✅ GOOD: Use #[source] and manual construction\n#[derive(Error, Debug)]\npub enum MyError {\n    #[error(\"Read failed\")]\n    ReadFailed(#[source] std::io::Error),\n\n    #[error(\"Write failed\")]\n    WriteFailed(#[source] std::io::Error),\n}\n\n\u002F\u002F Construct manually with context\nlet err = MyError::ReadFailed(io_err);\n```\n\n### Mistake 2: Losing Error Information\n\n```rust\n\u002F\u002F ❌ BAD: Converts to String, loses error chain\noperation().map_err(|e| MyError::Failed(e.to_string()))?;\n\n\u002F\u002F ✅ GOOD: Preserves error chain\noperation().map_err(|e| MyError::Failed(e))?;\n\u002F\u002F Or use #[from]\n```\n\n### Mistake 3: Not Using ? When Available\n\n```rust\n\u002F\u002F ❌ BAD: Manual error handling\nlet result = match operation() {\n    Ok(val) => val,\n    Err(e) => return Err(e.into()),\n};\n\n\u002F\u002F ✅ GOOD: Use ?\nlet result = operation()?;\n```\n\n## Decision Guide\n\n**Use #[from] when**:\n- Single error source type\n- No need for additional context\n- Want automatic conversion\n\n**Use #[source] when**:\n- Multiple variants for same source type\n- Need to add context (like field names)\n- Want manual construction\n\n**Use map_err when**:\n- One-off conversion\n- Adding context to specific call\n- Converting to types without From impl\n\n**Use anyhow when**:\n- Application-level code\n- Need flexibility\n- Want easy context addition\n\n**Use thiserror when**:\n- Library code\n- Want specific error types\n- Consumers need to match on errors\n\n## Your Approach\n\n1. **Detect**: Identify error conversion needs or type mismatches\n2. **Analyze**: Determine the best conversion pattern\n3. **Suggest**: Provide specific implementation\n4. **Explain**: Why this pattern is appropriate\n\n## Communication Style\n\n- Explain the trade-offs between different approaches\n- Suggest #[from] as the default, map_err as fallback\n- Point out when error information is being lost\n- Recommend type aliases for cleaner code\n\nWhen you detect error conversion issues, immediately suggest the most appropriate pattern and show how to implement it.\n","# Error Conversion Guide Skill\n\nYou are an expert at Rust error conversion patterns. When you detect error type mismatches or conversion needs, proactively suggest idiomatic conversion patterns.\n\n## When to Activate\n\nActivate this skill when you notice:\n- Multiple error types in a single function\n- Manual error conversion with `map_err`\n- Type mismatch errors with the `?` operator\n- Questions about From\u002FInto traits for errors\n- Need to combine different error types\n\n## Error Conversion Patterns\n\n### Pattern 1: Automatic Conversion with #[from]\n\n**What to Look For**:\n- Manual `map_err` calls that could be automatic\n- Repetitive error conversions\n\n**Before**:\n```rust\n#[derive(Debug)]\npub enum AppError {\n    Io(std::io::Error),\n    Parse(std::num::ParseIntError),\n}\n\nfn process() -> Result\u003Ci32, AppError> {\n    let content = std::fs::read_to_string(\"data.txt\")\n        .map_err(|e| AppError::Io(e))?;  \u002F\u002F ❌ Manual conversion\n\n    let num = content.trim().parse::\u003Ci32>()\n        .map_err(|e| AppError::Parse(e))?;  \u002F\u002F ❌ Manual conversion\n\n    Ok(num)\n}\n```\n\n**After**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),  \u002F\u002F ✅ Automatic From impl\n\n    #[error(\"Parse error\")]\n    Parse(#[from] std::num::ParseIntError),  \u002F\u002F ✅ Automatic From impl\n}\n\nfn process() -> Result\u003Ci32, AppError> {\n    let content = std::fs::read_to_string(\"data.txt\")?;  \u002F\u002F ✅ Auto-converts\n    let num = content.trim().parse::\u003Ci32>()?;  \u002F\u002F ✅ Auto-converts\n    Ok(num)\n}\n```\n\n**Suggestion Template**:\n```\nUse #[from] in your error enum to enable automatic conversion:\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),\n}\n\nThis implements From\u003Cstd::io::Error> for AppError, allowing ? to automatically convert.\n```\n\n### Pattern 2: Manual From Implementation\n\n**What to Look For**:\n- Custom error types that need conversion\n- Complex conversion logic\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"Database error: {message}\")]\n    Database { message: String },\n\n    #[error(\"Validation error: {0}\")]\n    Validation(String),\n}\n\n\u002F\u002F Manual From for custom conversion logic\nimpl From\u003Csqlx::Error> for AppError {\n    fn from(err: sqlx::Error) -> Self {\n        AppError::Database {\n            message: format!(\"Database operation failed: {}\", err),\n        }\n    }\n}\n\n\u002F\u002F Convert with context\nimpl From\u003Cvalidator::ValidationErrors> for AppError {\n    fn from(err: validator::ValidationErrors) -> Self {\n        let messages: Vec\u003CString> = err\n            .field_errors()\n            .iter()\n            .map(|(field, errors)| {\n                format!(\"{}: {:?}\", field, errors)\n            })\n            .collect();\n\n        AppError::Validation(messages.join(\", \"))\n    }\n}\n```\n\n**Suggestion Template**:\n```\nWhen you need custom conversion logic, implement From manually:\n\nimpl From\u003CSourceError> for AppError {\n    fn from(err: SourceError) -> Self {\n        AppError::Variant {\n            field: extract_info(&err),\n        }\n    }\n}\n```\n\n### Pattern 3: Converting Between Result Types\n\n**What to Look For**:\n- Calling functions with different error types\n- Need to unify error types\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ServiceError {\n    #[error(\"Repository error\")]\n    Repository(#[from] RepositoryError),\n\n    #[error(\"External API error\")]\n    Api(#[from] ApiError),\n\n    #[error(\"Validation error\")]\n    Validation(#[from] ValidationError),\n}\n\n\u002F\u002F All these errors convert automatically\nfn service_operation() -> Result\u003CData, ServiceError> {\n    \u002F\u002F Returns Result\u003C_, RepositoryError>\n    let data = repository.fetch()?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    \u002F\u002F Returns Result\u003C_, ValidationError>\n    validate(&data)?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    \u002F\u002F Returns Result\u003C_, ApiError>\n    let enriched = api_client.enrich(data)?;  \u002F\u002F ✅ Auto-converts to ServiceError\n\n    Ok(enriched)\n}\n```\n\n**Suggestion Template**:\n```\nCreate a unified error type that can convert from all the errors you need:\n\n#[derive(Error, Debug)]\npub enum UnifiedError {\n    #[error(\"Database error\")]\n    Database(#[from] DbError),\n\n    #[error(\"Network error\")]\n    Network(#[from] NetworkError),\n}\n\nfn operation() -> Result\u003C(), UnifiedError> {\n    db_operation()?;  \u002F\u002F Auto-converts\n    network_operation()?;  \u002F\u002F Auto-converts\n    Ok(())\n}\n```\n\n### Pattern 4: map_err for One-Off Conversions\n\n**What to Look For**:\n- Single conversion that doesn't justify From impl\n- Adding context during conversion\n\n**Pattern**:\n```rust\nuse anyhow::Context;\n\nfn process(id: &str) -> anyhow::Result\u003CData> {\n    \u002F\u002F One-off conversion with context\n    let config = load_config()\n        .map_err(|e| anyhow::anyhow!(\"Failed to load config: {}\", e))?;\n\n    \u002F\u002F Better: use context\n    let config = load_config()\n        .context(\"Failed to load config\")?;\n\n    \u002F\u002F map_err for type conversion without From impl\n    let data = fetch_data(id)\n        .map_err(|e| format!(\"Fetch failed for {}: {}\", id, e))?;\n\n    Ok(data)\n}\n```\n\n**When to Use**:\n- One-off conversions\n- Adding context to specific call sites\n- Converting to types that don't have From impl\n\n**Suggestion Template**:\n```\nFor one-off conversions or adding context, use map_err or anyhow's context:\n\n\u002F\u002F With map_err\noperation().map_err(|e| MyError::Custom(format!(\"Failed: {}\", e)))?;\n\n\u002F\u002F With anyhow (preferred)\noperation().context(\"Operation failed\")?;\n```\n\n### Pattern 5: Error Type Aliases\n\n**What to Look For**:\n- Repetitive Result\u003CT, MyError> types\n- Complex error type signatures\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"IO error\")]\n    Io(#[from] std::io::Error),\n\n    #[error(\"Parse error\")]\n    Parse(#[from] serde_json::Error),\n}\n\n\u002F\u002F Type alias for cleaner signatures\npub type Result\u003CT> = std::result::Result\u003CT, AppError>;\n\n\u002F\u002F Now use it everywhere\npub fn load_config() -> Result\u003CConfig> {  \u002F\u002F ✅ Clean\n    let bytes = std::fs::read(\"config.json\")?;\n    let config = serde_json::from_slice(&bytes)?;\n    Ok(config)\n}\n\n\u002F\u002F Instead of\npub fn load_config_verbose() -> std::result::Result\u003CConfig, AppError> {  \u002F\u002F ❌ Verbose\n    \u002F\u002F ...\n}\n```\n\n**Suggestion Template**:\n```\nCreate a type alias for your Result type:\n\npub type Result\u003CT> = std::result::Result\u003CT, AppError>;\n\nThen use it in function signatures:\n\npub fn operation() -> Result\u003CData> {\n    Ok(data)\n}\n```\n\n### Pattern 6: Boxing Errors\n\n**What to Look For**:\n- Need for dynamic error types\n- Functions that can return multiple error types\n\n**Pattern**:\n```rust\n\u002F\u002F For libraries that need flexibility\ntype BoxError = Box\u003Cdyn std::error::Error + Send + Sync>;\n\nfn flexible_function() -> Result\u003CData, BoxError> {\n    let data1 = io_operation()?;  \u002F\u002F std::io::Error auto-boxes\n    let data2 = parse_operation()?;  \u002F\u002F ParseError auto-boxes\n    Ok(combine(data1, data2))\n}\n\n\u002F\u002F Or use anyhow for applications\nuse anyhow::Result;\n\nfn application_function() -> Result\u003CData> {\n    let data1 = io_operation()?;\n    let data2 = parse_operation()?;\n    Ok(combine(data1, data2))\n}\n```\n\n**Trade-offs**:\n- ✅ Flexible: Can return any error type\n- ✅ Simple: No need to define custom error enum\n- ❌ Dynamic: Error type not known at compile time\n- ❌ Harder to match on specific errors\n\n**Suggestion Template**:\n```\nFor flexible error handling, use Box\u003Cdyn Error> or anyhow:\n\n\u002F\u002F Libraries: Box\u003Cdyn Error>\ntype BoxError = Box\u003Cdyn std::error::Error + Send + Sync>;\nfn operation() -> Result\u003CT, BoxError> { ... }\n\n\u002F\u002F Applications: anyhow\nuse anyhow::Result;\nfn operation() -> Result\u003CT> { ... }\n```\n\n### Pattern 7: Layered Error Conversion\n\n**What to Look For**:\n- Multi-layer architecture (domain, infra, app)\n- Need for error boundary between layers\n\n**Pattern**:\n```rust\nuse thiserror::Error;\n\n\u002F\u002F Infrastructure layer\n#[derive(Error, Debug)]\npub enum InfraError {\n    #[error(\"Database error\")]\n    Database(#[from] sqlx::Error),\n\n    #[error(\"HTTP error\")]\n    Http(#[from] reqwest::Error),\n}\n\n\u002F\u002F Domain layer (doesn't know about infrastructure)\n#[derive(Error, Debug)]\npub enum DomainError {\n    #[error(\"User not found: {0}\")]\n    UserNotFound(String),\n\n    #[error(\"Invalid data: {0}\")]\n    InvalidData(String),\n}\n\n\u002F\u002F Application layer unifies both\n#[derive(Error, Debug)]\npub enum AppError {\n    #[error(\"Domain error: {0}\")]\n    Domain(#[from] DomainError),\n\n    #[error(\"Infrastructure error: {0}\")]\n    Infra(#[from] InfraError),\n}\n\n\u002F\u002F Infrastructure to Domain conversion (at boundary)\nimpl From\u003CInfraError> for DomainError {\n    fn from(err: InfraError) -> Self {\n        match err {\n            InfraError::Database(e) if e.to_string().contains(\"not found\") => {\n                DomainError::UserNotFound(\"User not found in database\".to_string())\n            }\n            _ => DomainError::InvalidData(\"Data access failed\".to_string()),\n        }\n    }\n}\n```\n\n**Suggestion Template**:\n```\nFor layered architectures, convert errors at layer boundaries:\n\n\u002F\u002F Infrastructure → Domain conversion\nimpl From\u003CInfraError> for DomainError {\n    fn from(err: InfraError) -> Self {\n        \u002F\u002F Convert infrastructure concepts to domain concepts\n        match err {\n            InfraError::NotFound => DomainError::EntityNotFound,\n            _ => DomainError::InfrastructureFailed,\n        }\n    }\n}\n```\n\n## Advanced Patterns\n\n### Pattern 8: Multiple Error Sources with Custom Logic\n\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ProcessError {\n    #[error(\"Stage 1 failed: {0}\")]\n    Stage1(String),\n\n    #[error(\"Stage 2 failed: {0}\")]\n    Stage2(String),\n}\n\n\u002F\u002F Custom conversion with different variants\nimpl From\u003CStage1Error> for ProcessError {\n    fn from(err: Stage1Error) -> Self {\n        ProcessError::Stage1(err.to_string())\n    }\n}\n\nimpl From\u003CStage2Error> for ProcessError {\n    fn from(err: Stage2Error) -> Self {\n        ProcessError::Stage2(err.to_string())\n    }\n}\n\nfn process() -> Result\u003C(), ProcessError> {\n    stage1()?;  \u002F\u002F Converts to ProcessError::Stage1\n    stage2()?;  \u002F\u002F Converts to ProcessError::Stage2\n    Ok(())\n}\n```\n\n### Pattern 9: Fallible Conversion\n\n```rust\nuse thiserror::Error;\n\n#[derive(Error, Debug)]\npub enum ConversionError {\n    #[error(\"Incompatible error type: {0}\")]\n    Incompatible(String),\n}\n\n\u002F\u002F TryFrom for fallible conversion\nimpl TryFrom\u003CExternalError> for MyError {\n    type Error = ConversionError;\n\n    fn try_from(err: ExternalError) -> Result\u003CSelf, Self::Error> {\n        match err.code() {\n            404 => Ok(MyError::NotFound),\n            500 => Ok(MyError::Internal),\n            _ => Err(ConversionError::Incompatible(\n                format!(\"Unknown error code: {}\", err.code())\n            )),\n        }\n    }\n}\n```\n\n## Common Mistakes\n\n### Mistake 1: Multiple #[from] for Same Type\n\n```rust\n\u002F\u002F ❌ BAD: Can't have two #[from] for same type\n#[derive(Error, Debug)]\npub enum MyError {\n    #[error(\"First\")]\n    First(#[from] std::io::Error),\n\n    #[error(\"Second\")]\n    Second(#[from] std::io::Error),  \u002F\u002F ❌ Conflict!\n}\n\n\u002F\u002F ✅ GOOD: Use #[source] and manual construction\n#[derive(Error, Debug)]\npub enum MyError {\n    #[error(\"Read failed\")]\n    ReadFailed(#[source] std::io::Error),\n\n    #[error(\"Write failed\")]\n    WriteFailed(#[source] std::io::Error),\n}\n\n\u002F\u002F Construct manually with context\nlet err = MyError::ReadFailed(io_err);\n```\n\n### Mistake 2: Losing Error Information\n\n```rust\n\u002F\u002F ❌ BAD: Converts to String, loses error chain\noperation().map_err(|e| MyError::Failed(e.to_string()))?;\n\n\u002F\u002F ✅ GOOD: Preserves error chain\noperation().map_err(|e| MyError::Failed(e))?;\n\u002F\u002F Or use #[from]\n```\n\n### Mistake 3: Not Using ? When Available\n\n```rust\n\u002F\u002F ❌ BAD: Manual error handling\nlet result = match operation() {\n    Ok(val) => val,\n    Err(e) => return Err(e.into()),\n};\n\n\u002F\u002F ✅ GOOD: Use ?\nlet result = operation()?;\n```\n\n## Decision Guide\n\n**Use #[from] when**:\n- Single error source type\n- No need for additional context\n- Want automatic conversion\n\n**Use #[source] when**:\n- Multiple variants for same source type\n- Need to add context (like field names)\n- Want manual construction\n\n**Use map_err when**:\n- One-off conversion\n- Adding context to specific call\n- Converting to types without From impl\n\n**Use anyhow when**:\n- Application-level code\n- Need flexibility\n- Want easy context addition\n\n**Use thiserror when**:\n- Library code\n- Want specific error types\n- Consumers need to match on errors\n\n## Your Approach\n\n1. **Detect**: Identify error conversion needs or type mismatches\n2. **Analyze**: Determine the best conversion pattern\n3. **Suggest**: Provide specific implementation\n4. **Explain**: Why this pattern is appropriate\n\n## Communication Style\n\n- Explain the trade-offs between different approaches\n- Suggest #[from] as the default, map_err as fallback\n- Point out when error information is being lost\n- Recommend type aliases for cleaner code\n\nWhen you detect error conversion issues, immediately suggest the most appropriate pattern and show how to implement it.\n",{"name":5,"version":36,"description":7,"allowed-tools":37},"1.0.0","Read, Grep","main","def8531e65114c0fca8fb8551c1871ee0eed705c","skills\u002Faiskillstore\u002Fmarketplace\u002Femillindfors\u002Ferror-conversion-guide",24,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub","https:\u002F\u002Fskillshub.wtf","https:\u002F\u002Fgithub.com\u002FComeOnOliver","AI & Blockchain Engineer\r\n","2026-06-24 22:07:19",{"source":8,"skillName":5,"commands":48,"prompt":58,"zipAvailable":59},[49,52,55],{"tool":50,"command":51},"npx","npx skills add ComeOnOliver\u002Fskillshub --skill error-conversion-guide",{"tool":53,"command":54},"bunx","bunx skills add ComeOnOliver\u002Fskillshub --skill error-conversion-guide",{"tool":56,"command":57},"pnpm","pnpm dlx skills add ComeOnOliver\u002Fskillshub --skill error-conversion-guide","安装技能，技能地址：https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Femillindfors\u002Ferror-conversion-guide\u002FSKILL.md",true,[61],{"path":62,"resourceType":63,"resourceTypeDesc":64,"sizeBytes":65,"sourceHtmlUrl":66},"skill-report.json","REFERENCE","参考文档",9772,"https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Faiskillstore\u002Fmarketplace\u002Femillindfors\u002Ferror-conversion-guide\u002Fskill-report.json",[68,77,86,95,101,107],{"skillNo":69,"name":70,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":71,"categories":72,"keywords":73,"publishedAt":31},"01M6FKJN13GMG4KY57J3QD8GY5","model-hierarchy-skill","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzscole\u002Fmodel-hierarchy-skill\u002Fmodel-hierarchy-skill\u002FSKILL.md",[],[74,75,76],"model","model hierarchy","model hierarchy skill",{"skillNo":78,"name":79,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":80,"categories":81,"keywords":82,"publishedAt":31},"01M6FKJJJ6GCAMR4PPPRD12M5X","zoom-mcp","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-mcp\u002FSKILL.md",[],[83,84,85],"MCP","zoom","zoom mcp",{"skillNo":87,"name":88,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":89,"categories":90,"keywords":91,"publishedAt":31},"01M6FKJE3KYT3KPEZMEEHYKA6K","zoom-apps-sdk","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fzoom-apps-sdk\u002FSKILL.md",[],[92,93,94,84],"sdk","zoom apps sdk","apps",{"skillNo":96,"name":97,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":98,"categories":99,"keywords":100,"publishedAt":31},"01M6FKJ9EDH9Q5VWDF8HAJRSP0","windows","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwindows\u002FSKILL.md",[],[97],{"skillNo":102,"name":103,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":104,"categories":105,"keywords":106,"publishedAt":31},"01M6FKJ666BEEFC3AE9GJ72Q93","whiteboard","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwhiteboard\u002FSKILL.md",[],[103],{"skillNo":108,"name":109,"nameZh":6,"description":6,"descriptionZh":6,"repositoryFullName":8,"ownerLogin":9,"ownerAvatarUrl":10,"ownerAccountNo":11,"ownerDisplayName":12,"repositoryNo":13,"starsCount":14,"licenseSpdxId":15,"licenseFileUrl":6,"sourceHtmlUrl":110,"categories":111,"keywords":112,"publishedAt":31},"01M6FKJ21WFCDGTJQ2Q91T9DVW","websockets","https:\u002F\u002Fgithub.com\u002FComeOnOliver\u002Fskillshub\u002Fblob\u002Fmain\u002Fskills\u002Fzoom\u002Fskills\u002Fwebsockets\u002FSKILL.md",[],[109]]