CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-eccodes

Python interface to the ecCodes GRIB and BUFR decoder/encoder library for meteorological data processing

Pending
Overview
Eval results
Files

error-handling.mddocs/

Error Handling

Comprehensive exception hierarchy for handling all types of errors that can occur during GRIB/BUFR processing, from file access issues to data validation failures.

Exception Hierarchy

Base Exceptions

class EcCodesError(Exception):
    """Base exception for all ecCodes errors."""

class GribInternalError(EcCodesError):
    """Internal error in GRIB processing."""

class BufferTooSmallError(EcCodesError):
    """Buffer size insufficient for operation."""

File and I/O Errors

class FileNotFoundError(EcCodesError):
    """File not found or cannot be opened."""

class IOProblemError(EcCodesError):
    """Input/output operation failed."""

class InvalidFileError(EcCodesError):
    """File format is invalid or corrupted."""

class PrematureEndOfFileError(EcCodesError):
    """Unexpected end of file encountered."""

Data Access Errors

class KeyValueNotFoundError(EcCodesError):
    """Requested key not found in message."""

class InvalidKeyValueError(EcCodesError):
    """Key value is invalid or out of range."""

class ReadOnlyError(EcCodesError):
    """Attempted to modify read-only key."""

class WrongArraySizeError(EcCodesError):
    """Array size mismatch in operation."""

Message Processing Errors

class InvalidMessageError(EcCodesError):
    """Message format is invalid."""

class DecodingError(EcCodesError):
    """Error decoding message data."""

class EncodingError(EcCodesError):
    """Error encoding message data."""

class UnsupportedEditionError(EcCodesError):
    """Unsupported GRIB/BUFR edition."""

Memory and Resource Errors

class OutOfMemoryError(EcCodesError):
    """Insufficient memory for operation."""

class NullHandleError(EcCodesError):
    """Invalid or null message handle."""

class InvalidArgumentError(EcCodesError):
    """Invalid argument passed to function."""

Usage Examples

Robust File Processing

import eccodes
from eccodes import EcCodesError, FileNotFoundError, KeyValueNotFoundError

def safe_read_grib(filename):
    try:
        with open(filename, 'rb') as f:
            msg = eccodes.codes_grib_new_from_file(f)
            if msg is None:
                print("No messages found in file")
                return None
            
            # Safe key access
            try:
                param_id = eccodes.codes_get(msg, 'paramId')
                level = eccodes.codes_get(msg, 'level')
                print(f"Parameter {param_id} at level {level}")
            except KeyValueNotFoundError as e:
                print(f"Key not found: {e}")
            
            eccodes.codes_release(msg)
            
    except FileNotFoundError:
        print(f"File not found: {filename}")
    except InvalidFileError:
        print(f"Invalid file format: {filename}")
    except EcCodesError as e:
        print(f"ecCodes error: {e}")

# Usage
safe_read_grib('forecast.grib')

Install with Tessl CLI

npx tessl i tessl/pypi-eccodes

docs

data-manipulation.md

error-handling.md

high-level-interface.md

index.md

indexing-search.md

key-value-access.md

message-operations.md

tile.json