Exceptions
All custom exceptions raised by Streamlit Lightweight Charts Pro.
Exception Hierarchy
StreamlitLightweightChartsProError (base)
├── ConfigurationError
│ ├── ComponentNotAvailableError
│ └── InvalidConfigurationError
├── ValidationError
│ ├── InvalidDataError
│ ├── InvalidColorError
│ ├── InvalidSeriesTypeError
│ └── InvalidCoordinateError
└── DataProcessingError
├── SerializationError
└── DataTransformError
Exception Classes
Custom exception classes for the Streamlit Lightweight Charts Pro library.
This module defines custom exception classes specific to the Streamlit wrapper while also re-exporting core exceptions from the lightweight_charts_pro package. The exception hierarchy provides clear, specific error messages for various validation and configuration issues that may occur during chart creation.
- Exception Hierarchy:
ValidationError (base) ├── TypeValidationError │ ├── DataItemsTypeError │ ├── AnnotationItemsTypeError (Streamlit-specific) │ ├── SeriesItemsTypeError (Streamlit-specific) │ ├── PriceScaleIdTypeError (Streamlit-specific) │ ├── PriceScaleOptionsTypeError (Streamlit-specific) │ ├── InstanceTypeError (Streamlit-specific) │ ├── TypeMismatchError (Streamlit-specific) │ └── TrendDirectionIntegerError (Streamlit-specific) ├── ValueValidationError │ ├── ColorValidationError │ ├── TimeValidationError │ ├── RangeValidationError │ └── ExitTimeAfterEntryTimeError (Streamlit-specific) ├── RequiredFieldError ├── DataFrameValidationError └── BaseValueFormatError (Streamlit-specific) ConfigurationError (base) ├── ComponentNotAvailableError (Streamlit-specific) ├── NpmNotFoundError (Streamlit-specific) └── CliNotFoundError (Streamlit-specific)
- Usage Example:
```python from streamlit_lightweight_charts_pro.exceptions import (
ComponentNotAvailableError, ValidationError,
)
- try:
# Component creation logic if not component_available:
raise ComponentNotAvailableError()
- except ComponentNotAvailableError as e:
st.error(str(e))
For more information, see the lightweight_charts_pro.exceptions module.
- exception streamlit_lightweight_charts_pro.exceptions.AnnotationItemsTypeError[source]
Bases:
TypeValidationErrorRaised when annotation items are not of the correct Annotation type.
This exception is thrown when attempting to add annotations to a chart but the provided items are not instances of the Annotation class. All annotation items must be valid Annotation objects.
- exception streamlit_lightweight_charts_pro.exceptions.BaseValueFormatError[source]
Bases:
ValidationErrorRaised when a baseline chart base value has invalid format.
Baseline charts require a base value dict with specific ‘type’ and ‘price’ keys. This exception is raised when the base value doesn’t match this required format.
- exception streamlit_lightweight_charts_pro.exceptions.CliNotFoundError[source]
Bases:
ConfigurationErrorRaised when the CLI command is not found in the system PATH.
This exception occurs when attempting to run CLI commands but the streamlit-lightweight-charts-pro CLI is not available in the system PATH. This typically indicates an installation issue.
Example
- if not shutil.which(“streamlit-lightweight-charts-pro”):
raise CliNotFoundError()
- exception streamlit_lightweight_charts_pro.exceptions.ColorValidationError[source]
Bases:
ValidationErrorRaised when color format is invalid.
This exception is used when a color value doesn’t match expected formats (hex or rgba).
- Parameters:
Example
>>> raise ColorValidationError("backgroundColor", "invalid") # Error: Invalid color format for backgroundColor: 'invalid'. # Must be hex or rgba.
- exception streamlit_lightweight_charts_pro.exceptions.ColumnMappingRequiredError[source]
Bases:
RequiredFieldErrorRaised when column mapping is required but not provided.
This exception is used when DataFrame or Series data is provided without the necessary column mapping configuration.
Example
>>> raise ColumnMappingRequiredError() # Error: column_mapping is required when providing DataFrame or # Series data is required
- exception streamlit_lightweight_charts_pro.exceptions.ComponentNotAvailableError[source]
Bases:
ConfigurationErrorRaised when the Streamlit component function is not available.
This exception occurs when the component fails to initialize properly, typically due to missing frontend assets or incorrect installation. It extends ConfigurationError to indicate a setup/configuration issue.
- exception streamlit_lightweight_charts_pro.exceptions.ConfigurationError[source]
Bases:
ExceptionBase exception for configuration-related errors.
This exception is raised when there are issues with system configuration, environment setup, or package initialization.
- Parameters:
message (str) – Descriptive error message explaining the configuration issue.
Example
>>> raise ConfigurationError("Invalid configuration detected")
- exception streamlit_lightweight_charts_pro.exceptions.DataFrameValidationError[source]
Bases:
ValidationErrorRaised when DataFrame validation fails.
This exception provides helper methods for common DataFrame validation errors like missing columns or invalid data types.
Example
>>> error = DataFrameValidationError.missing_column("price") >>> raise error # Error: DataFrame is missing required column: price
- classmethod invalid_data_type(data_type)[source]
Create error for invalid data type.
- Parameters:
data_type (type) – The invalid data type provided.
- Returns:
Configured error instance.
- Return type:
Example
>>> error = DataFrameValidationError.invalid_data_type(str) >>> raise error
- classmethod missing_column(column)[source]
Create error for missing DataFrame column.
- Parameters:
column (str) – Name of the missing column.
- Returns:
Configured error instance.
- Return type:
Example
>>> error = DataFrameValidationError.missing_column("time") >>> raise error
- classmethod missing_columns_mapping(missing_columns, required, mapping)[source]
Create error for missing columns in mapping.
- Parameters:
- Returns:
Configured error instance.
- Return type:
Example
>>> error = DataFrameValidationError.missing_columns_mapping( ... ["price"], ["time", "price"], {"time": "timestamp"} ... ) >>> raise error
- exception streamlit_lightweight_charts_pro.exceptions.DataItemsTypeError[source]
Bases:
TypeValidationErrorRaised when data items are not correct type.
This exception indicates that items in a data list are not instances of Data class or its subclasses.
Example
>>> raise DataItemsTypeError() # Error: All items in data list must be instances of Data or its # subclasses
- exception streamlit_lightweight_charts_pro.exceptions.DuplicateError[source]
Bases:
ValidationErrorRaised when duplicate values are detected.
This exception is used when a unique constraint is violated, such as duplicate IDs, names, or other identifiers.
- Parameters:
field_name (str) – Name of the field where duplicate was detected.
value (Any) – The duplicate value.
Example
>>> raise DuplicateError("series_id", "main") # Error: Duplicate series_id: main
- exception streamlit_lightweight_charts_pro.exceptions.ExitTimeAfterEntryTimeError[source]
Bases:
ValueValidationErrorRaised when a trade’s exit time is not after its entry time.
In trade visualization, the exit time must chronologically follow the entry time. This exception is raised when this constraint is violated, which would result in an invalid or confusing trade representation.
- exception streamlit_lightweight_charts_pro.exceptions.InstanceTypeError[source]
Bases:
TypeValidationErrorRaised when a value must be an instance of a specific type.
This is a general-purpose type validation exception for checking that values are instances of expected classes. Optionally allows None values when allow_none is True.
Example
```python if not isinstance(value, ChartOptions):
raise InstanceTypeError(“options”, ChartOptions, allow_none=True)
- exception streamlit_lightweight_charts_pro.exceptions.InvalidMarkerPositionError[source]
Bases:
ValidationErrorRaised when marker position is invalid.
Example
>>> raise InvalidMarkerPositionError("top", "circle") # Error: Invalid position 'top' for marker type circle
- exception streamlit_lightweight_charts_pro.exceptions.NotFoundError[source]
Bases:
ValidationErrorRaised when a requested resource is not found.
- Parameters:
Example
>>> raise NotFoundError("Series", "main-series") # Error: Series with identifier 'main-series' not found
- exception streamlit_lightweight_charts_pro.exceptions.NpmNotFoundError[source]
Bases:
ConfigurationErrorRaised when NPM is not found in the system PATH.
Building the frontend assets requires Node.js and NPM to be installed. This exception is raised when attempting to build frontend assets but NPM cannot be found in the system PATH.
- exception streamlit_lightweight_charts_pro.exceptions.PriceScaleIdTypeError[source]
Bases:
TypeValidationErrorRaised when a price scale ID is not a string.
Price scale IDs must be string values to properly identify and reference different price scales in multi-series charts. This exception is raised when a non-string value is provided as a price scale identifier.
- exception streamlit_lightweight_charts_pro.exceptions.PriceScaleOptionsTypeError[source]
Bases:
TypeValidationErrorRaised when price scale options are not a PriceScaleOptions object.
Price scale configuration must be provided as a PriceScaleOptions instance. This exception is raised when an invalid type is provided for price scale options, such as a dict or other object type.
- exception streamlit_lightweight_charts_pro.exceptions.RangeValidationError[source]
Bases:
ValueValidationErrorRaised when value is outside valid range.
This exception is used for numeric range validation, supporting minimum-only, maximum-only, or bounded ranges.
- Parameters:
Example
>>> raise RangeValidationError("opacity", 1.5, 0.0, 1.0) # Error: opacity must be between 0.0 and 1.0, got 1.5
- exception streamlit_lightweight_charts_pro.exceptions.RequiredFieldError[source]
Bases:
ValidationErrorRaised when a required field is missing.
This exception indicates that a mandatory field was not provided when creating or updating an object.
- Parameters:
field_name (str) – Name of the required field that is missing.
Example
>>> raise RequiredFieldError("title") # Error: title is required
- exception streamlit_lightweight_charts_pro.exceptions.SeriesItemsTypeError[source]
Bases:
TypeValidationErrorRaised when series items are not of the correct Series type.
This exception occurs when trying to add series to a chart but the provided items are not valid Series instances. All series must inherit from the base Series class (e.g., LineSeries, CandlestickSeries).
- exception streamlit_lightweight_charts_pro.exceptions.TimeValidationError[source]
Bases:
ValidationErrorRaised when time validation fails.
This exception is used for time-related validation errors such as invalid time strings or unsupported time types.
- Parameters:
message (str) – Description of the time validation failure.
Example
>>> raise TimeValidationError("Invalid timestamp format") # Error: Time validation failed: Invalid timestamp format
- __init__(message)[source]
Initialize TimeValidationError.
- Parameters:
message (str) – Time validation failure description.
- classmethod invalid_time_string(time_value)[source]
Create error for invalid time string.
- Parameters:
time_value (str) – The invalid time string.
- Returns:
Configured error instance.
- Return type:
Example
>>> error = TimeValidationError.invalid_time_string("not-a-date") >>> raise error
- exception streamlit_lightweight_charts_pro.exceptions.TrendDirectionIntegerError[source]
Bases:
TypeValidationErrorRaised when a trend direction value is not an integer.
Trend direction indicators must be integer values (typically -1, 0, or 1) to represent bearish, neutral, or bullish trends. This exception is raised when a non-integer value is provided for trend direction.
- exception streamlit_lightweight_charts_pro.exceptions.TypeMismatchError[source]
Bases:
TypeValidationErrorRaised when there is a type mismatch between expected and actual types.
This exception is used for strict type checking where the actual type does not match the expected type. Unlike InstanceTypeError, this checks for exact type matches rather than instance relationships.
- exception streamlit_lightweight_charts_pro.exceptions.TypeValidationError[source]
Bases:
ValidationErrorRaised when type validation fails.
This exception is used when a value is of an incorrect type. It provides formatted error messages that clearly indicate what type was expected versus what was received.
- Parameters:
Example
>>> raise TypeValidationError("price", "float", "str") # Error: price must be float, got str
- exception streamlit_lightweight_charts_pro.exceptions.UnsupportedTimeTypeError[source]
Bases:
TypeValidationErrorRaised when time type is unsupported.
- Parameters:
time_type (type) – The unsupported time type.
Example
>>> raise UnsupportedTimeTypeError(list) # Error: time unsupported type, got list
- exception streamlit_lightweight_charts_pro.exceptions.ValidationError[source]
Bases:
ExceptionBase exception for all validation errors.
This is the root exception class for all validation-related errors in the package. It should be caught when you want to handle any type of validation failure.
- Parameters:
message (str) – Descriptive error message explaining the validation failure.
Example
>>> raise ValidationError("Invalid input provided")
- exception streamlit_lightweight_charts_pro.exceptions.ValueValidationError[source]
Bases:
ValidationErrorRaised when value validation fails.
This class provides helper methods for common validation patterns, reducing the need for overly specific exception classes. It handles validations like positive numbers, ranges, and required fields.
- Parameters:
Example
>>> error = ValueValidationError.positive_value("price", -10) >>> raise error # Error: price must be positive, got -10
- classmethod in_range(field_name, min_val, max_val, value)[source]
Create error for out-of-range value.
Helper method for validating that a value falls within a specified range [min_val, max_val].
- Parameters:
- Returns:
Configured error instance.
- Return type:
Example
>>> error = ValueValidationError.in_range("percentage", 0, 100, 150) >>> raise error
- classmethod non_negative_value(field_name, value=None)[source]
Create error for negative value.
Helper method for validating that a value is non-negative (>= 0).
- Parameters:
- Returns:
Configured error instance.
- Return type:
Example
>>> error = ValueValidationError.non_negative_value("count", -1) >>> raise error
- classmethod positive_value(field_name, value)[source]
Create error for non-positive value.
Helper method for validating that a value is positive (> 0).
- Parameters:
- Returns:
Configured error instance.
- Return type:
Example
>>> error = ValueValidationError.positive_value("price", -5) >>> raise error
- classmethod required_field(field_name)[source]
Create error for missing required field.
Helper method for validating that a required field is present.
- Parameters:
field_name (str) – Name of the required field.
- Returns:
Configured error instance.
- Return type:
Example
>>> error = ValueValidationError.required_field("title") >>> raise error
Usage Examples
Catching specific exceptions:
from streamlit_lightweight_charts_pro import renderChart
from streamlit_lightweight_charts_pro.exceptions import (
InvalidDataError,
InvalidColorError
)
try:
renderChart(data, lineColor="invalid-color")
except InvalidColorError as e:
st.error(f"Invalid color: {e}")
except InvalidDataError as e:
st.error(f"Data error: {e}")
Catching all package exceptions:
from streamlit_lightweight_charts_pro.exceptions import (
StreamlitLightweightChartsProError
)
try:
renderChart(data)
except StreamlitLightweightChartsProError as e:
st.error(f"Chart error: {e}")