reifydb-sub-flow 0.10.2

Flow subsystem for stream processing and data flows
Documentation
// SPDX-License-Identifier: Apache-2.0
// Copyright (c) 2026 ReifyDB

use reifydb_core::error::diagnostic::flow::{
	extern_abi_tag_mismatch, extern_create_failed, extern_library_load_failed, extern_library_not_loaded,
	extern_operator_not_found, extern_symbol_not_found,
};
use reifydb_value::error::{Diagnostic, Error, IntoDiagnostic};

#[derive(Debug, thiserror::Error)]
pub enum ExternOperatorError {
	#[error("extern operator ABI tag mismatch: plugin {plugin:#06x}, host {host:#06x}")]
	AbiTagMismatch {
		plugin: u32,
		host: u32,
	},

	#[error("extern operator library not loaded: {path}")]
	LibraryNotLoaded {
		path: String,
	},

	#[error("extern operator library failed to load: {path}: {cause}")]
	LibraryLoadFailed {
		path: String,
		cause: String,
	},

	#[error("extern operator symbol '{symbol}' not found: {cause}")]
	SymbolNotFound {
		symbol: &'static str,
		cause: String,
	},

	#[error("extern operator '{operator}' not found")]
	OperatorNotFound {
		operator: String,
	},

	#[error("failed to create extern operator: {cause}")]
	CreateFailed {
		cause: String,
	},
}

impl IntoDiagnostic for ExternOperatorError {
	fn into_diagnostic(self) -> Diagnostic {
		match self {
			ExternOperatorError::AbiTagMismatch {
				plugin,
				host,
			} => extern_abi_tag_mismatch(plugin, host),
			ExternOperatorError::LibraryNotLoaded {
				path,
			} => extern_library_not_loaded(&path),
			ExternOperatorError::LibraryLoadFailed {
				path,
				cause,
			} => extern_library_load_failed(&path, cause),
			ExternOperatorError::SymbolNotFound {
				symbol,
				cause,
			} => extern_symbol_not_found(symbol, cause),
			ExternOperatorError::OperatorNotFound {
				operator,
			} => extern_operator_not_found(&operator),
			ExternOperatorError::CreateFailed {
				cause,
			} => extern_create_failed(cause),
		}
	}
}

impl From<ExternOperatorError> for Error {
	fn from(err: ExternOperatorError) -> Self {
		Error(Box::new(err.into_diagnostic()))
	}
}