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 DMSC. The DMSC 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 DMSC, including the DMSCError enum and DMSCResult type alias. It defines a comprehensive set of error variants for different error scenarios encountered in the DMSC library.

§Key Components

  • DMSCError: Enum representing all possible errors in DMSC
  • DMSCResult: Type alias for Result<T, DMSCError> used throughout the library

§Design Principles

  1. Comprehensive Coverage: Covers all major error categories encountered in DMSC
  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 dmsc::prelude::*;
 
fn example_function() -> DMSCResult<()> {
    // Return a custom error
    Err(DMSCError::Other("An error occurred"))
}
 
#[tokio::main]
async fn main() -> DMSCResult<()> {
    match example_function() {
        Ok(_) => println!("Success"),
        Err(err) => {
            println!("Error: {}", err);
            Err(err)
        }
    }
}

Structs§

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

Enums§

DMSCError
Core error type for DMSC. 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§

DMSCResult
Result type alias for DMSC operations. Used throughout the library.