Skip to main content

pipeline/
error.rs

1// Copyright 2023 Greptime Team
2//
3// Licensed under the Apache License, Version 2.0 (the "License");
4// you may not use this file except in compliance with the License.
5// You may obtain a copy of the License at
6//
7//     http://www.apache.org/licenses/LICENSE-2.0
8//
9// Unless required by applicable law or agreed to in writing, software
10// distributed under the License is distributed on an "AS IS" BASIS,
11// WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12// See the License for the specific language governing permissions and
13// limitations under the License.
14
15use std::any::Any;
16
17use common_error::ext::ErrorExt;
18use common_error::status_code::StatusCode;
19use common_macro::stack_trace_debug;
20use datatypes::timestamp::TimestampNanosecond;
21use snafu::{Location, Snafu};
22use vrl::value::Kind;
23
24#[derive(Snafu)]
25#[snafu(visibility(pub))]
26#[stack_trace_debug]
27pub enum Error {
28    #[snafu(display("Empty input field"))]
29    EmptyInputField {
30        #[snafu(implicit)]
31        location: Location,
32    },
33
34    #[snafu(display("Missing input field"))]
35    MissingInputField {
36        #[snafu(implicit)]
37        location: Location,
38    },
39
40    #[snafu(display(
41        "Field renaming must be a string pair of 'key' and 'rename_to', got: {value:?}"
42    ))]
43    InvalidFieldRename {
44        value: yaml_rust::Yaml,
45        #[snafu(implicit)]
46        location: Location,
47    },
48
49    #[snafu(display("Processor must be a map"))]
50    ProcessorMustBeMap {
51        #[snafu(implicit)]
52        location: Location,
53    },
54
55    #[snafu(display("Processor {processor}: missing field: {field}"))]
56    ProcessorMissingField {
57        processor: String,
58        field: String,
59        #[snafu(implicit)]
60        location: Location,
61    },
62
63    #[snafu(display("Processor {processor}: expect string value, but got {v:?}"))]
64    ProcessorExpectString {
65        processor: String,
66        v: vrl::value::Value,
67        #[snafu(implicit)]
68        location: Location,
69    },
70
71    #[snafu(display("Processor {processor}: unsupported value {val}"))]
72    ProcessorUnsupportedValue {
73        processor: String,
74        val: String,
75        #[snafu(implicit)]
76        location: Location,
77    },
78
79    #[snafu(display("Processor key must be a string"))]
80    ProcessorKeyMustBeString {
81        #[snafu(implicit)]
82        location: Location,
83    },
84
85    #[snafu(display("Processor {kind}: failed to parse {value}"))]
86    ProcessorFailedToParseString {
87        kind: String,
88        value: String,
89        #[snafu(implicit)]
90        location: Location,
91    },
92
93    #[snafu(display("Processor must have a string key"))]
94    ProcessorMustHaveStringKey {
95        #[snafu(implicit)]
96        location: Location,
97    },
98
99    #[snafu(display("Unsupported {processor} processor"))]
100    UnsupportedProcessor {
101        processor: String,
102        #[snafu(implicit)]
103        location: Location,
104    },
105
106    #[snafu(display("Field {field} must be a {ty}"))]
107    FieldMustBeType {
108        field: String,
109        ty: String,
110        #[snafu(implicit)]
111        location: Location,
112    },
113
114    #[snafu(display("Field parse from string failed: {field}"))]
115    FailedParseFieldFromString {
116        #[snafu(source)]
117        error: Box<dyn std::error::Error + Send + Sync>,
118        field: String,
119        #[snafu(implicit)]
120        location: Location,
121    },
122
123    #[snafu(display("Failed to parse {key} as int: {value}"))]
124    FailedToParseIntKey {
125        key: String,
126        value: String,
127        #[snafu(source)]
128        error: std::num::ParseIntError,
129        #[snafu(implicit)]
130        location: Location,
131    },
132
133    #[snafu(display("Failed to parse {value} to int"))]
134    FailedToParseInt {
135        value: String,
136        #[snafu(source)]
137        error: std::num::ParseIntError,
138        #[snafu(implicit)]
139        location: Location,
140    },
141    #[snafu(display("Failed to parse {key} as float: {value}"))]
142    FailedToParseFloatKey {
143        key: String,
144        value: String,
145        #[snafu(source)]
146        error: std::num::ParseFloatError,
147        #[snafu(implicit)]
148        location: Location,
149    },
150
151    #[snafu(display("Processor {kind}: {key} not found in intermediate keys"))]
152    IntermediateKeyIndex {
153        kind: String,
154        key: String,
155        #[snafu(implicit)]
156        location: Location,
157    },
158
159    #[snafu(display("Cmcd {k} missing value in {s}"))]
160    CmcdMissingValue {
161        k: String,
162        s: String,
163        #[snafu(implicit)]
164        location: Location,
165    },
166    #[snafu(display("Part: {part} missing key in {s}"))]
167    CmcdMissingKey {
168        part: String,
169        s: String,
170        #[snafu(implicit)]
171        location: Location,
172    },
173    #[snafu(display("Key must be a string, but got {k:?}"))]
174    KeyMustBeString {
175        k: yaml_rust::Yaml,
176        #[snafu(implicit)]
177        location: Location,
178    },
179
180    #[snafu(display("Csv read error"))]
181    CsvRead {
182        #[snafu(implicit)]
183        location: Location,
184        #[snafu(source)]
185        error: csv::Error,
186    },
187    #[snafu(display("Expected at least one record from csv format, but got none"))]
188    CsvNoRecord {
189        #[snafu(implicit)]
190        location: Location,
191    },
192
193    #[snafu(display("Separator '{separator}' must be a single character, but got '{value}'"))]
194    CsvSeparatorName {
195        separator: String,
196        value: String,
197        #[snafu(implicit)]
198        location: Location,
199    },
200
201    #[snafu(display("Quote '{quote}' must be a single character, but got '{value}'"))]
202    CsvQuoteName {
203        quote: String,
204        value: String,
205        #[snafu(implicit)]
206        location: Location,
207    },
208
209    #[snafu(display("Parse date timezone error {value}"))]
210    DateParseTimezone {
211        value: String,
212        #[snafu(source)]
213        error: chrono_tz::ParseError,
214        #[snafu(implicit)]
215        location: Location,
216    },
217
218    #[snafu(display("Parse date error {value}"))]
219    DateParse {
220        value: String,
221        #[snafu(source)]
222        error: chrono::ParseError,
223        #[snafu(implicit)]
224        location: Location,
225    },
226
227    #[snafu(display("Failed to get local timezone"))]
228    DateFailedToGetLocalTimezone {
229        #[snafu(implicit)]
230        location: Location,
231    },
232
233    #[snafu(display("Invalid Pattern: '{s}'. {detail}"))]
234    DissectInvalidPattern {
235        s: String,
236        detail: String,
237        #[snafu(implicit)]
238        location: Location,
239    },
240
241    #[snafu(display("Empty pattern is not allowed"))]
242    DissectEmptyPattern {
243        #[snafu(implicit)]
244        location: Location,
245    },
246    #[snafu(display("Split: '{split}' exceeds the input"))]
247    DissectSplitExceedsInput {
248        split: String,
249        #[snafu(implicit)]
250        location: Location,
251    },
252    #[snafu(display("Split: '{split}' does not match the input '{input}'"))]
253    DissectSplitNotMatchInput {
254        split: String,
255        input: String,
256        #[snafu(implicit)]
257        location: Location,
258    },
259    #[snafu(display("Consecutive names are not allowed: '{name1}' '{name2}'"))]
260    DissectConsecutiveNames {
261        name1: String,
262        name2: String,
263        #[snafu(implicit)]
264        location: Location,
265    },
266    #[snafu(display("No matching pattern found"))]
267    DissectNoMatchingPattern {
268        #[snafu(implicit)]
269        location: Location,
270    },
271    #[snafu(display("Modifier '{m}' already set, but found {modifier}"))]
272    DissectModifierAlreadySet {
273        m: String,
274        modifier: String,
275        #[snafu(implicit)]
276        location: Location,
277    },
278
279    #[snafu(display("Append Order modifier is already set to '{n}', cannot be set to {order}"))]
280    DissectAppendOrderAlreadySet {
281        n: String,
282        order: u32,
283        #[snafu(implicit)]
284        location: Location,
285    },
286    #[snafu(display("Order can only be set to Append Modifier, current modifier is {m}"))]
287    DissectOrderOnlyAppend {
288        m: String,
289        #[snafu(implicit)]
290        location: Location,
291    },
292
293    #[snafu(display("Order can only be set to Append Modifier"))]
294    DissectOrderOnlyAppendModifier {
295        #[snafu(implicit)]
296        location: Location,
297    },
298
299    #[snafu(display("End modifier already set: '{m}'"))]
300    DissectEndModifierAlreadySet {
301        m: String,
302        #[snafu(implicit)]
303        location: Location,
304    },
305    #[snafu(display("Invalid resolution: {resolution}"))]
306    EpochInvalidResolution {
307        resolution: String,
308        #[snafu(implicit)]
309        location: Location,
310    },
311    #[snafu(display("Pattern is required"))]
312    GsubPatternRequired {
313        #[snafu(implicit)]
314        location: Location,
315    },
316    #[snafu(display("Replacement is required"))]
317    GsubReplacementRequired {
318        #[snafu(implicit)]
319        location: Location,
320    },
321    #[snafu(display("Invalid regex pattern: {pattern}"))]
322    Regex {
323        #[snafu(source)]
324        error: regex::Error,
325        pattern: String,
326        #[snafu(implicit)]
327        location: Location,
328    },
329    #[snafu(display("Separator is required"))]
330    JoinSeparatorRequired {
331        #[snafu(implicit)]
332        location: Location,
333    },
334    #[snafu(display("Invalid method: {method}"))]
335    LetterInvalidMethod {
336        method: String,
337        #[snafu(implicit)]
338        location: Location,
339    },
340    #[snafu(display("No named group found in regex {origin}"))]
341    RegexNamedGroupNotFound {
342        origin: String,
343        #[snafu(implicit)]
344        location: Location,
345    },
346    #[snafu(display("No valid field found in {processor} processor"))]
347    RegexNoValidField {
348        processor: String,
349        #[snafu(implicit)]
350        location: Location,
351    },
352    #[snafu(display("No valid pattern found in {processor} processor"))]
353    RegexNoValidPattern {
354        processor: String,
355        #[snafu(implicit)]
356        location: Location,
357    },
358    #[snafu(display("Invalid method: {s}"))]
359    UrlEncodingInvalidMethod {
360        s: String,
361        #[snafu(implicit)]
362        location: Location,
363    },
364    #[snafu(display("Wrong digest pattern: {pattern}"))]
365    DigestPatternInvalid {
366        pattern: String,
367        #[snafu(implicit)]
368        location: Location,
369    },
370    #[snafu(display("Invalid transform on_failure value: {value}"))]
371    TransformOnFailureInvalidValue {
372        value: String,
373        #[snafu(implicit)]
374        location: Location,
375    },
376    #[snafu(display("Transform element must be a map"))]
377    TransformElementMustBeMap {
378        #[snafu(implicit)]
379        location: Location,
380    },
381    #[snafu(display("Transform fields must be set."))]
382    TransformFieldMustBeSet {
383        #[snafu(implicit)]
384        location: Location,
385    },
386    #[snafu(display("Transform {fields:?} type MUST BE set."))]
387    TransformTypeMustBeSet {
388        fields: String,
389        #[snafu(implicit)]
390        location: Location,
391    },
392    #[snafu(display("Invalid JSON2 type hint: {reason}"))]
393    InvalidJson2TypeHint {
394        reason: String,
395        #[snafu(implicit)]
396        location: Location,
397    },
398    #[snafu(display("Invalid JSON2 type hint path '{path}'"))]
399    ParseJson2TypeHintPath {
400        path: String,
401        #[snafu(source)]
402        source: sql::error::Error,
403        #[snafu(implicit)]
404        location: Location,
405    },
406    #[snafu(display("Transform index `type` must be set."))]
407    TransformIndexTypeMustBeSet {
408        #[snafu(implicit)]
409        location: Location,
410    },
411    #[snafu(display("Unsupported field in transform index config: {field}"))]
412    TransformIndexUnsupportedField {
413        field: String,
414        #[snafu(implicit)]
415        location: Location,
416    },
417    #[snafu(display(
418        "Transform index option `{field}` must be a string, boolean, integer, or real scalar"
419    ))]
420    TransformIndexOptionMustBeScalar {
421        field: String,
422        #[snafu(implicit)]
423        location: Location,
424    },
425    #[snafu(display("Index type `{index}` does not support options in pipeline config"))]
426    TransformIndexOptionsUnsupported {
427        index: String,
428        #[snafu(implicit)]
429        location: Location,
430    },
431    #[snafu(display("Unsupported option `{key}` for `{index}` index"))]
432    TransformIndexOptionUnsupported {
433        index: String,
434        key: String,
435        #[snafu(implicit)]
436        location: Location,
437    },
438    #[snafu(display("Index `{index}` only supports {expected} columns, but got {actual}"))]
439    TransformIndexTypeMismatch {
440        index: String,
441        expected: String,
442        actual: String,
443        #[snafu(implicit)]
444        location: Location,
445    },
446    #[snafu(display("Invalid options for `{index}` index"))]
447    TransformIndexOption {
448        index: String,
449        #[snafu(source)]
450        source: datatypes::error::Error,
451        #[snafu(implicit)]
452        location: Location,
453    },
454    #[snafu(display("Transform index `{index}` does not match options declared for `{options}`"))]
455    TransformIndexStateMismatch {
456        index: String,
457        options: String,
458        #[snafu(implicit)]
459        location: Location,
460    },
461    #[snafu(display("Column name must be unique, but got duplicated: {duplicates}"))]
462    TransformColumnNameMustBeUnique {
463        duplicates: String,
464        #[snafu(implicit)]
465        location: Location,
466    },
467    #[snafu(display(
468        "Illegal to set multiple timestamp Index columns, please set only one: {columns}"
469    ))]
470    TransformMultipleTimestampIndex {
471        columns: String,
472        #[snafu(implicit)]
473        location: Location,
474    },
475    #[snafu(display(
476        "Transform must have exactly one field specified as timestamp Index, but got {count}: {columns}"
477    ))]
478    TransformTimestampIndexCount {
479        count: usize,
480        columns: String,
481        #[snafu(implicit)]
482        location: Location,
483    },
484    #[snafu(display(
485        "Exactly one time-related processor and one timestamp value is required to use auto transform. `ignore_missing` can not be set to true."
486    ))]
487    AutoTransformOneTimestamp {
488        #[snafu(implicit)]
489        location: Location,
490    },
491    #[snafu(display("Invalid Pipeline doc version number: {}", version))]
492    InvalidVersionNumber {
493        version: String,
494        #[snafu(implicit)]
495        location: Location,
496    },
497    #[snafu(display("Type: {ty} value not supported for Epoch"))]
498    CoerceUnsupportedEpochType {
499        ty: String,
500        #[snafu(implicit)]
501        location: Location,
502    },
503    #[snafu(display("Failed to coerce string value '{s}' to type '{ty}'"))]
504    CoerceStringToType {
505        s: String,
506        ty: String,
507        #[snafu(implicit)]
508        location: Location,
509    },
510    #[snafu(display("Can not coerce json type to {ty}"))]
511    CoerceJsonTypeTo {
512        ty: String,
513        #[snafu(implicit)]
514        location: Location,
515    },
516    #[snafu(display(
517        "Can not coerce {ty} to json type. we only consider object and array to be json types."
518    ))]
519    CoerceTypeToJson {
520        ty: String,
521        #[snafu(implicit)]
522        location: Location,
523    },
524    #[snafu(display("Failed to coerce value: {msg}"))]
525    CoerceIncompatibleTypes {
526        msg: String,
527        #[snafu(implicit)]
528        location: Location,
529    },
530    #[snafu(display(
531        "Invalid resolution: '{resolution}'. Available resolutions: {valid_resolution}"
532    ))]
533    ValueInvalidResolution {
534        resolution: String,
535        valid_resolution: String,
536        #[snafu(implicit)]
537        location: Location,
538    },
539
540    #[snafu(display("Failed to parse type: '{t}'"))]
541    ValueParseType {
542        t: String,
543        #[snafu(implicit)]
544        location: Location,
545    },
546
547    #[snafu(display("Failed to parse {ty}: {v}"))]
548    ValueParseInt {
549        ty: String,
550        v: String,
551        #[snafu(source)]
552        error: std::num::ParseIntError,
553        #[snafu(implicit)]
554        location: Location,
555    },
556
557    #[snafu(display("Failed to parse {ty}: {v}"))]
558    ValueParseFloat {
559        ty: String,
560        v: String,
561        #[snafu(source)]
562        error: std::num::ParseFloatError,
563        #[snafu(implicit)]
564        location: Location,
565    },
566
567    #[snafu(display("Failed to parse {ty}: {v}"))]
568    ValueParseBoolean {
569        ty: String,
570        v: String,
571        #[snafu(source)]
572        error: std::str::ParseBoolError,
573        #[snafu(implicit)]
574        location: Location,
575    },
576    #[snafu(display("Default value not unsupported for type {value}"))]
577    ValueDefaultValueUnsupported {
578        value: String,
579        #[snafu(implicit)]
580        location: Location,
581    },
582
583    #[snafu(display("Unsupported yaml type: {value:?}"))]
584    ValueUnsupportedYamlType {
585        value: yaml_rust::Yaml,
586        #[snafu(implicit)]
587        location: Location,
588    },
589
590    #[snafu(display("key in Hash must be a string, but got {value:?}"))]
591    ValueYamlKeyMustBeString {
592        value: yaml_rust::Yaml,
593        #[snafu(implicit)]
594        location: Location,
595    },
596
597    #[snafu(display("Yaml load error."))]
598    YamlLoad {
599        #[snafu(source)]
600        error: yaml_rust::ScanError,
601        #[snafu(implicit)]
602        location: Location,
603    },
604    #[snafu(display("Yaml parse error."))]
605    YamlParse {
606        #[snafu(implicit)]
607        location: Location,
608    },
609    #[snafu(display("Column options error"))]
610    ColumnOptions {
611        #[snafu(source)]
612        source: api::error::Error,
613        #[snafu(implicit)]
614        location: Location,
615    },
616    #[snafu(display("Unsupported index type: {value}"))]
617    UnsupportedIndexType {
618        value: String,
619        #[snafu(implicit)]
620        location: Location,
621    },
622    #[snafu(display("Failed to parse logfmt input: {input}, reason: {reason}"))]
623    LogfmtParse {
624        input: String,
625        reason: String,
626        #[snafu(implicit)]
627        location: Location,
628    },
629    #[snafu(display("Failed to parse json"))]
630    JsonParse {
631        #[snafu(source)]
632        error: serde_json::Error,
633        #[snafu(implicit)]
634        location: Location,
635    },
636    #[snafu(display(
637        "Column datatype mismatch. For column: {column}, expected datatype: {expected}, actual datatype: {actual}"
638    ))]
639    IdentifyPipelineColumnTypeMismatch {
640        column: String,
641        expected: String,
642        actual: String,
643        #[snafu(implicit)]
644        location: Location,
645    },
646    #[snafu(display("Parse json path error"))]
647    JsonPathParse {
648        #[snafu(implicit)]
649        location: Location,
650        #[snafu(source)]
651        error: jsonpath_rust::JsonPathParserError,
652    },
653    #[snafu(display("Json path result index not number"))]
654    JsonPathParseResultIndex {
655        #[snafu(implicit)]
656        location: Location,
657    },
658    #[snafu(display("Field is required for dispatcher"))]
659    FieldRequiredForDispatcher,
660    #[snafu(display("Table_suffix is required for dispatcher rule"))]
661    TableSuffixRequiredForDispatcherRule,
662    #[snafu(display("Value is required for dispatcher rule"))]
663    ValueRequiredForDispatcherRule,
664
665    #[snafu(display("Pipeline table not found"))]
666    PipelineTableNotFound {
667        #[snafu(implicit)]
668        location: Location,
669    },
670
671    #[snafu(display("Failed to insert pipeline to pipelines table"))]
672    InsertPipeline {
673        #[snafu(source)]
674        source: operator::error::Error,
675        #[snafu(implicit)]
676        location: Location,
677    },
678
679    #[snafu(display("Pipeline not found, name: {}, version: {}", name, version.map(|ts| ts.0.to_iso8601_string()).unwrap_or("latest".to_string())))]
680    PipelineNotFound {
681        name: String,
682        version: Option<TimestampNanosecond>,
683        #[snafu(implicit)]
684        location: Location,
685    },
686
687    #[snafu(display(
688        "Multiple pipelines with different schemas found, but none under current schema. Please replicate one of them or delete until only one schema left. name: {}, current_schema: {}, schemas: {}",
689        name,
690        current_schema,
691        schemas,
692    ))]
693    MultiPipelineWithDiffSchema {
694        name: String,
695        current_schema: String,
696        schemas: String,
697        #[snafu(implicit)]
698        location: Location,
699    },
700
701    #[snafu(display(
702        "The return value's length of the record batch does not match, see debug log for details"
703    ))]
704    RecordBatchLenNotMatch {
705        #[snafu(implicit)]
706        location: Location,
707    },
708
709    /// `try_get_with` shares one loader across concurrent misses, so its error
710    /// arrives behind an `Arc`.
711    #[snafu(display("Failed to load pipeline into cache: {}", error))]
712    CacheLoad {
713        error: std::sync::Arc<Error>,
714        #[snafu(implicit)]
715        location: Location,
716    },
717
718    #[snafu(display("Failed to collect record batch"))]
719    CollectRecords {
720        #[snafu(implicit)]
721        location: Location,
722        #[snafu(source)]
723        source: common_recordbatch::error::Error,
724    },
725
726    #[snafu(display("A valid table suffix template is required for tablesuffix section"))]
727    RequiredTableSuffixTemplate,
728
729    #[snafu(display("Invalid table suffix template, input: {}", input))]
730    InvalidTableSuffixTemplate {
731        input: String,
732        #[snafu(implicit)]
733        location: Location,
734    },
735
736    #[snafu(display("Failed to compile VRL, {}", msg))]
737    CompileVrl {
738        msg: String,
739        #[snafu(implicit)]
740        location: Location,
741    },
742
743    #[snafu(display("Failed to execute VRL, {}", msg))]
744    ExecuteVrl {
745        msg: String,
746        #[snafu(implicit)]
747        location: Location,
748    },
749    #[snafu(display("Invalid timestamp value: {}", input))]
750    InvalidTimestamp {
751        input: String,
752        #[snafu(implicit)]
753        location: Location,
754    },
755
756    #[snafu(display("Invalid epoch value '{}' for resolution '{}'", value, resolution))]
757    InvalidEpochForResolution {
758        value: i64,
759        resolution: String,
760        #[snafu(implicit)]
761        location: Location,
762    },
763    #[snafu(display("Please don't use regex in Vrl script"))]
764    VrlRegexValue {
765        #[snafu(implicit)]
766        location: Location,
767    },
768
769    #[snafu(display(
770        "Vrl script should return object or array in the end, got `{:?}`",
771        result_kind
772    ))]
773    VrlReturnValue {
774        result_kind: Kind,
775        #[snafu(implicit)]
776        location: Location,
777    },
778
779    #[snafu(display("Failed to cast type, msg: {}", msg))]
780    CastType {
781        msg: String,
782        #[snafu(implicit)]
783        location: Location,
784    },
785
786    #[snafu(display("Top level value must be map"))]
787    ValueMustBeMap {
788        #[snafu(implicit)]
789        location: Location,
790    },
791
792    #[snafu(display(
793        "Array element at index {index} must be an object for one-to-many transformation, got {actual_type}"
794    ))]
795    ArrayElementMustBeObject {
796        index: usize,
797        actual_type: String,
798        #[snafu(implicit)]
799        location: Location,
800    },
801
802    #[snafu(display("Failed to transform array element at index {index}: {source}"))]
803    TransformArrayElement {
804        index: usize,
805        #[snafu(source)]
806        source: Box<Error>,
807        #[snafu(implicit)]
808        location: Location,
809    },
810
811    #[snafu(display("Failed to build DataFusion logical plan"))]
812    BuildDfLogicalPlan {
813        #[snafu(source)]
814        error: datafusion_common::DataFusionError,
815        #[snafu(implicit)]
816        location: Location,
817    },
818
819    #[snafu(display("Failed to execute internal statement"))]
820    ExecuteInternalStatement {
821        #[snafu(source)]
822        source: query::error::Error,
823        #[snafu(implicit)]
824        location: Location,
825    },
826
827    #[snafu(display("Failed to create dataframe"))]
828    DataFrame {
829        #[snafu(source)]
830        source: query::error::Error,
831        #[snafu(implicit)]
832        location: Location,
833    },
834
835    #[snafu(display("General catalog error"))]
836    Catalog {
837        #[snafu(source)]
838        source: catalog::error::Error,
839        #[snafu(implicit)]
840        location: Location,
841    },
842
843    #[snafu(display("Failed to create table"))]
844    CreateTable {
845        #[snafu(source)]
846        source: operator::error::Error,
847        #[snafu(implicit)]
848        location: Location,
849    },
850
851    #[snafu(display("Invalid pipeline version format: {}", version))]
852    InvalidPipelineVersion {
853        version: String,
854        #[snafu(implicit)]
855        location: Location,
856    },
857
858    #[snafu(display("Invalid custom time index config: {}, reason: {}", config, reason))]
859    InvalidCustomTimeIndex {
860        config: String,
861        reason: String,
862        #[snafu(implicit)]
863        location: Location,
864    },
865
866    #[snafu(display("Pipeline is required for this API."))]
867    PipelineMissing {
868        #[snafu(implicit)]
869        location: Location,
870    },
871
872    #[snafu(display("Time index must be non null."))]
873    TimeIndexMustBeNonNull {
874        #[snafu(implicit)]
875        location: Location,
876    },
877
878    #[snafu(display("Float is NaN"))]
879    FloatIsNan {
880        #[snafu(source)]
881        error: ordered_float::FloatIsNan,
882        #[snafu(implicit)]
883        location: Location,
884    },
885
886    #[snafu(display("Unsupported type in pipeline: {}", ty))]
887    UnsupportedTypeInPipeline {
888        ty: String,
889        #[snafu(implicit)]
890        location: Location,
891    },
892
893    #[snafu(transparent)]
894    GreptimeProto {
895        source: api::error::Error,
896        #[snafu(implicit)]
897        location: Location,
898    },
899
900    #[snafu(transparent)]
901    Datatypes {
902        source: datatypes::error::Error,
903        #[snafu(implicit)]
904        location: Location,
905    },
906}
907
908pub type Result<T> = std::result::Result<T, Error>;
909
910impl ErrorExt for Error {
911    fn status_code(&self) -> StatusCode {
912        use Error::*;
913        match self {
914            CacheLoad { error, .. } => error.status_code(),
915            CastType { .. } => StatusCode::Unexpected,
916            PipelineTableNotFound { .. } => StatusCode::TableNotFound,
917            InsertPipeline { source, .. } => source.status_code(),
918            CollectRecords { source, .. } => source.status_code(),
919            PipelineNotFound { .. }
920            | InvalidPipelineVersion { .. }
921            | InvalidCustomTimeIndex { .. }
922            | TimeIndexMustBeNonNull { .. } => StatusCode::InvalidArguments,
923            MultiPipelineWithDiffSchema { .. }
924            | ValueMustBeMap { .. }
925            | ArrayElementMustBeObject { .. } => StatusCode::IllegalState,
926            TransformArrayElement { source, .. } => source.status_code(),
927            BuildDfLogicalPlan { .. } | RecordBatchLenNotMatch { .. } => StatusCode::Internal,
928            ExecuteInternalStatement { source, .. } => source.status_code(),
929            DataFrame { source, .. } => source.status_code(),
930            Catalog { source, .. } => source.status_code(),
931            CreateTable { source, .. } => source.status_code(),
932
933            EmptyInputField { .. }
934            | MissingInputField { .. }
935            | InvalidFieldRename { .. }
936            | ProcessorMustBeMap { .. }
937            | ProcessorMissingField { .. }
938            | ProcessorExpectString { .. }
939            | ProcessorUnsupportedValue { .. }
940            | ProcessorKeyMustBeString { .. }
941            | ProcessorFailedToParseString { .. }
942            | ProcessorMustHaveStringKey { .. }
943            | UnsupportedProcessor { .. }
944            | FieldMustBeType { .. }
945            | FailedParseFieldFromString { .. }
946            | FailedToParseIntKey { .. }
947            | FailedToParseInt { .. }
948            | FailedToParseFloatKey { .. }
949            | IntermediateKeyIndex { .. }
950            | CmcdMissingValue { .. }
951            | CmcdMissingKey { .. }
952            | KeyMustBeString { .. }
953            | CsvRead { .. }
954            | CsvNoRecord { .. }
955            | CsvSeparatorName { .. }
956            | CsvQuoteName { .. }
957            | DateParseTimezone { .. }
958            | DateParse { .. }
959            | DateFailedToGetLocalTimezone { .. }
960            | DissectInvalidPattern { .. }
961            | DissectEmptyPattern { .. }
962            | DissectSplitExceedsInput { .. }
963            | DissectSplitNotMatchInput { .. }
964            | DissectConsecutiveNames { .. }
965            | DissectNoMatchingPattern { .. }
966            | DissectModifierAlreadySet { .. }
967            | DissectAppendOrderAlreadySet { .. }
968            | DissectOrderOnlyAppend { .. }
969            | DissectOrderOnlyAppendModifier { .. }
970            | DissectEndModifierAlreadySet { .. }
971            | EpochInvalidResolution { .. }
972            | GsubPatternRequired { .. }
973            | GsubReplacementRequired { .. }
974            | Regex { .. }
975            | JoinSeparatorRequired { .. }
976            | LetterInvalidMethod { .. }
977            | RegexNamedGroupNotFound { .. }
978            | RegexNoValidField { .. }
979            | RegexNoValidPattern { .. }
980            | UrlEncodingInvalidMethod { .. }
981            | DigestPatternInvalid { .. }
982            | TransformOnFailureInvalidValue { .. }
983            | TransformElementMustBeMap { .. }
984            | TransformFieldMustBeSet { .. }
985            | TransformTypeMustBeSet { .. }
986            | InvalidJson2TypeHint { .. }
987            | ParseJson2TypeHintPath { .. }
988            | TransformIndexTypeMustBeSet { .. }
989            | TransformIndexUnsupportedField { .. }
990            | TransformIndexOptionMustBeScalar { .. }
991            | TransformIndexOptionsUnsupported { .. }
992            | TransformIndexOptionUnsupported { .. }
993            | TransformIndexTypeMismatch { .. }
994            | TransformIndexOption { .. }
995            | TransformIndexStateMismatch { .. }
996            | TransformColumnNameMustBeUnique { .. }
997            | TransformMultipleTimestampIndex { .. }
998            | TransformTimestampIndexCount { .. }
999            | AutoTransformOneTimestamp { .. }
1000            | InvalidVersionNumber { .. }
1001            | CoerceUnsupportedEpochType { .. }
1002            | CoerceStringToType { .. }
1003            | CoerceJsonTypeTo { .. }
1004            | CoerceTypeToJson { .. }
1005            | CoerceIncompatibleTypes { .. }
1006            | ValueInvalidResolution { .. }
1007            | ValueParseType { .. }
1008            | ValueParseInt { .. }
1009            | ValueParseFloat { .. }
1010            | ValueParseBoolean { .. }
1011            | ValueDefaultValueUnsupported { .. }
1012            | ValueUnsupportedYamlType { .. }
1013            | ValueYamlKeyMustBeString { .. }
1014            | YamlLoad { .. }
1015            | YamlParse { .. }
1016            | ColumnOptions { .. }
1017            | UnsupportedIndexType { .. }
1018            | IdentifyPipelineColumnTypeMismatch { .. }
1019            | JsonParse { .. }
1020            | LogfmtParse { .. }
1021            | JsonPathParse { .. }
1022            | JsonPathParseResultIndex { .. }
1023            | FieldRequiredForDispatcher
1024            | TableSuffixRequiredForDispatcherRule
1025            | ValueRequiredForDispatcherRule
1026            | RequiredTableSuffixTemplate
1027            | InvalidTableSuffixTemplate { .. }
1028            | CompileVrl { .. }
1029            | ExecuteVrl { .. }
1030            | InvalidTimestamp { .. }
1031            | VrlRegexValue { .. }
1032            | VrlReturnValue { .. }
1033            | PipelineMissing { .. } => StatusCode::InvalidArguments,
1034
1035            FloatIsNan { .. }
1036            | InvalidEpochForResolution { .. }
1037            | UnsupportedTypeInPipeline { .. } => StatusCode::InvalidArguments,
1038
1039            GreptimeProto { source, .. } => source.status_code(),
1040            Datatypes { source, .. } => source.status_code(),
1041        }
1042    }
1043
1044    fn as_any(&self) -> &dyn Any {
1045        self
1046    }
1047}