From 7aed482ee01e2377a9c5c6e2cbd680713a7e91db Mon Sep 17 00:00:00 2001 From: Florian Bernd Date: Wed, 26 Apr 2023 21:05:32 +0200 Subject: [PATCH] Add playground region (#2) --- pkg/plugin/query.go | 37 ++++++++++++++++++++++----------- src/components/ConfigEditor.tsx | 30 +++++++++++++++++++------- 2 files changed, 47 insertions(+), 20 deletions(-) diff --git a/pkg/plugin/query.go b/pkg/plugin/query.go index c7566a4..480436c 100644 --- a/pkg/plugin/query.go +++ b/pkg/plugin/query.go @@ -444,6 +444,10 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e index := 0 for reader.Next() { + if status != nil { + return nil, errors.New("unexpected data after ::final_status annotation") + } + if reader.Type() != ion.StructType { return nil, fmt.Errorf("expected 'struct' type, got '%s'", reader.Type().String()) } @@ -454,7 +458,8 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e } // Fail on unexpected annotations - if len(annotations) != 0 && (len(annotations) != 1 || annotations[0].Text == nil || *annotations[0].Text != "final_status") { + if len(annotations) != 0 && (len(annotations) != 1 || annotations[0].Text == nil || + (*annotations[0].Text != "final_status" && *annotations[0].Text != "query_error")) { labels := make([]string, len(annotations)) for i := range annotations { if annotations[0].Text != nil { @@ -471,18 +476,26 @@ func iterateRows(input io.Reader, readRowFn func(reader ion.Reader, index int) e return nil, err } - // Parse ::final_status annotation - if len(annotations) != 0 { - status, err = readFinalStatus(reader) + if len(annotations) == 0 { + // Process data row + err = readRowFn(reader, index) if err != nil { return nil, err } - } - - // Process data row - err = readRowFn(reader, index) - if err != nil { - return nil, err + } else { + if *annotations[0].Text != "final_status" { + // Parse ::final_status annotation + status, err = readFinalStatus(reader) + if err != nil { + return nil, err + } + } else { + // Parse ::query_error annotation + status, err = readFinalStatus(reader) + if err != nil { + return nil, err + } + } } err = reader.StepOut() @@ -531,14 +544,14 @@ func readFinalStatus(reader ion.Reader) (*snellerFinalStatus, error) { status.Scanned = *value case "result_set": // Ignore for now - case "error": + case "error", "error_message": value, err := reader.StringValue() if err != nil { return nil, err } status.Error = *value default: - return nil, fmt.Errorf("unexpected ::final_status field '%s'", name) + return nil, fmt.Errorf("unexpected ::final_status or ::query_error field '%s'", name) } } diff --git a/src/components/ConfigEditor.tsx b/src/components/ConfigEditor.tsx index 1b9a6cb..ec7faf9 100644 --- a/src/components/ConfigEditor.tsx +++ b/src/components/ConfigEditor.tsx @@ -30,6 +30,10 @@ export function ConfigEditor(props: Props) { label: 'Europe (Ireland)', value: 'eu-west-1' }, + { + label: 'Playground', + value: 'play' + }, { label: 'Custom Endpoint', value: 'custom', @@ -37,15 +41,25 @@ export function ConfigEditor(props: Props) { ]; const onRegionChange = (value: SelectableValue, actionMeta: ActionMeta) => { - let endpoint = (value.value === 'custom') - ? options.jsonData.endpoint - : `https://snellerd-master.${value.value}.sneller-dev.io` + let endpoint = '' + switch (value.value) { + case 'custom': + endpoint = '' + break + case 'play': + endpoint = `https://play.sneller.io` + break + default: + endpoint = `https://snellerd-production.${value.value}.sneller.io` + break + } const jsonData = { ...options.jsonData, region: value.value, endpoint: endpoint, }; + onOptionsChange({ ...options, jsonData }); }; @@ -86,29 +100,29 @@ export function ConfigEditor(props: Props) { return (
- + - +