1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
//! Common types and utilities for JMESPath extension functions.
//!
//! This module provides helper functions and re-exports for implementing custom JMESPath functions.
//!
//! # Error Handling
//!
//! When implementing custom functions, use these helpers for consistent error messages:
//!
//! - [`invalid_type_error`] - For type mismatches (produces structured `RuntimeError::InvalidType`)
//! - [`custom_error`] - For domain-specific errors (e.g., "Invalid regex pattern")
//!
//! ## Example
//!
//! ```ignore
//! impl Function for MyFn {
//! fn evaluate(&self, args: &[Rcvar], ctx: &mut Context<'_>) -> Result<Rcvar, JmespathError> {
//! self.signature.validate(args, ctx)?;
//!
//! // After signature validation, type checks are guaranteed to pass.
//! // Use unwrap() for validated types, or invalid_type_error() for custom validation.
//! let s = args[0].as_string().unwrap();
//!
//! // For domain-specific errors:
//! if s.is_empty() {
//! return Err(custom_error(ctx, "String cannot be empty"));
//! }
//!
//! Ok(Rc::new(Variable::String(s.to_uppercase())))
//! }
//! }
//! ```
use Rc;
pub use RuntimeError;
pub use ;
pub use ;
/// Creates a JmespathError for an invalid argument type.
///
/// This produces a structured `RuntimeError::InvalidType` error which provides
/// better debugging information than a generic parse error string.
///
/// # Arguments
/// * `ctx` - The evaluation context
/// * `position` - The argument position (0-indexed)
/// * `expected` - Description of the expected type(s)
/// * `actual` - The actual value that was provided
///
/// # Example
/// ```ignore
/// let err = invalid_type_error(ctx, 0, "string", &args[0]);
/// ```
/// Creates a JmespathError for a custom runtime error message.
///
/// Use this for domain-specific errors that don't fit the standard error types,
/// such as "Invalid regex pattern" or "Division by zero".
///
/// # Arguments
/// * `ctx` - The evaluation context
/// * `message` - A descriptive error message
///
/// # Example
/// ```ignore
/// let err = custom_error(ctx, "Invalid regex pattern: unclosed group");
/// ```
/// Helper macro for defining JMESPath custom functions.
///
/// This macro creates a struct with a signature field and implements
/// the necessary boilerplate for creating new JMESPath functions.
}
}
};
}
/// Helper to create an Rcvar from a Variable
/// Helper macro for registering a function only if it's in the enabled set.
///
/// This is used by `register_filtered` functions to conditionally register
/// functions based on the registry's enabled/disabled state.