Skip to main content

Module error

Module error 

Source
Expand description

Error types for astro-math calculations.

Handles validation and error reporting for coordinate conversions, time calculations, and astronomical computations.

§Error Types

The main error type is AstroError, which covers all possible errors in the crate:

  • Coordinate errors: Invalid RA, Dec, latitude, or longitude values
  • Range errors: Values outside acceptable ranges for calculations
  • Format errors: Invalid string formats (e.g., DMS parsing)
  • Calculation errors: Mathematical failures or edge cases
  • Projection errors: Points that cannot be projected

§Examples

use astro_math::error::{AstroError, validate_ra, validate_dec};

// Validate coordinates before use
match validate_ra(400.0) {
    Ok(_) => println!("Valid RA"),
    Err(e) => println!("Error: {}", e), // "Invalid RA: 400 (valid range: [0, 360))"
}

// Functions return Result types
use astro_math::{ra_dec_to_alt_az, Location};
use chrono::Utc;

let location = Location { latitude_deg: 40.0, longitude_deg: -74.0, altitude_m: 0.0 };
let result = ra_dec_to_alt_az(400.0, 45.0, Utc::now(), &location);
 
match result {
    Ok((alt, az)) => println!("Alt: {}, Az: {}", alt, az),
    Err(AstroError::InvalidCoordinate { coord_type, value, .. }) => {
        println!("Invalid {}: {}", coord_type, value);
    }
    Err(e) => println!("Other error: {}", e),
}

Enums§

AstroError
Main error type for astro-math operations.

Functions§

validate_coordinate_safe
Comprehensive coordinate validation including finite check
validate_dec
Validate declination (-90 <= Dec <= 90).
validate_finite
Validate that a floating point value is finite (not NaN or infinite)
validate_latitude
Validate latitude (-90 <= lat <= 90)
validate_longitude
Validate longitude (-180 <= lon <= 180)
validate_ra
Validate right ascension (0 <= RA < 360).
validate_range
Validate that a value is within a range.

Type Aliases§

Result
Type alias for Results in this crate.