Skip to main content

Module error

Module error 

Source
Expand description

Error handling with custom error types and result aliases Copyright © 2025-2026 Wenze Wei. All Rights Reserved.

This file is part of Ri. The Ri project belongs to the Dunimd Team.

Licensed under the Apache License, Version 2.0 (the “License”); You may not use this file except in compliance with the License. You may obtain a copy of the License at

http://www.apache.org/licenses/LICENSE-2.0

Unless required by applicable law or agreed to in writing, software distributed under the License is distributed on an “AS IS” BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. See the License for the specific language governing permissions and limitations under the License.

§Error Handling

This module provides the core error handling types for Ri, including the RiError enum and RiResult type alias. It defines a comprehensive set of error variants for different error scenarios encountered in the Ri library.

§Key Components

  • RiError: Enum representing all possible errors in Ri
  • RiResult: Type alias for Result<T, RiError> used throughout the library

§Design Principles

  1. Comprehensive Coverage: Covers all major error categories encountered in Ri
  2. Type Safety: Each error variant provides specific context about the error
  3. Easy Conversion: Implements From traits for common external error types
  4. Human-Readable: Provides clear, descriptive error messages
  5. Standard Compliance: Implements std::error::Error and std::fmt::Display

§Usage

use ri::prelude::*;
 
fn example_function() -> RiResult<()> {
    // Return a custom error
    Err(RiError::Other("An error occurred"))
}
 
#[tokio::main]
async fn main() -> RiResult<()> {
    match example_function() {
        Ok(_) => println!("Success"),
        Err(err) => {
            println!("Error: {}", err);
            Err(err)
        }
    }
}

Structs§

RiErrorFormatter
Enhanced error formatting with suggestions. Provides consistent error messages with actionable suggestions for resolution.

Enums§

RiError
Core error type for Ri. Represents all possible errors that can occur in the library.

Functions§

format_error
Formats an error with actionable suggestion. This helper function provides enhanced error messages that include suggestions for resolving the issue.
log_error
Logs an error with enhanced formatting. This helper function logs the error with its suggestion for debugging.

Type Aliases§

RiResult
Result type alias for Ri operations. Used throughout the library.