From 1a3aafa015800c6474b0b005fad8c0aecbd230d5 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Fri, 30 Jun 2023 16:01:48 -0400 Subject: [PATCH 1/2] fix: propagate and display invalid JSON errors in VRL web playground --- .../web-playground/public/.gitignore | 2 +- .../web-playground/public/README.md | 19 ++++++------ lib/vector-vrl/web-playground/public/index.js | 31 ++++++++++++++++--- .../web-playground/public/package.json | 6 ++-- 4 files changed, 39 insertions(+), 19 deletions(-) diff --git a/lib/vector-vrl/web-playground/public/.gitignore b/lib/vector-vrl/web-playground/public/.gitignore index de695ce7d35fc..f59ec20aabf58 100644 --- a/lib/vector-vrl/web-playground/public/.gitignore +++ b/lib/vector-vrl/web-playground/public/.gitignore @@ -1 +1 @@ -vector_vrl_web_playground** +* \ No newline at end of file diff --git a/lib/vector-vrl/web-playground/public/README.md b/lib/vector-vrl/web-playground/public/README.md index b042c0f4a26db..9354b77321205 100644 --- a/lib/vector-vrl/web-playground/public/README.md +++ b/lib/vector-vrl/web-playground/public/README.md @@ -53,15 +53,16 @@ Some functions of VRL are not supported or don't work as expected at the moment due to WASM limitations with some Rust crates, in the future we will modify the functions so that they are supported. -List of functions that aren't supported at the moment: - -- `log()` -- `decrypt()` -- `encrypt()` -- `get_hostname()` -- `parse_groks()` -- `random_bytes()` -- `reverse_dns()` +List of functions that aren't supported at the moment. All of them exist, +but they will either error (enrichment functions) or abort (all the others) at runtime. + +- `log` +- `get_hostname` +- `parse_grok` +- `parse_groks` +- `reverse_dns` +- `find_enrichment_table_records` +- `get_enrichment_table_record` Functions from VRL stdlib that are currently not supported can be found with this [issue filter][vrl-wasm-unsupported-filter] diff --git a/lib/vector-vrl/web-playground/public/index.js b/lib/vector-vrl/web-playground/public/index.js index 6f69af1c6ab98..c30f64368e476 100644 --- a/lib/vector-vrl/web-playground/public/index.js +++ b/lib/vector-vrl/web-playground/public/index.js @@ -100,13 +100,29 @@ export class VrlWebPlayground { program: this.programEditor.getValue(), event: this.eventEditor.getModel().getLinesContent().join("\n"), is_jsonl: true, + error: null, }; } - return { - program: this.programEditor.getValue(), - event: JSON.parse((this.eventEditor.getValue().length == 0) ? "{}" : this.eventEditor.getValue()), - is_jsonl: false, - }; + + const editorValue = this.eventEditor.getValue(); + try { + return { + program: this.programEditor.getValue(), + event: JSON.parse((editorValue.length === 0) ? "{}" : editorValue), + is_jsonl: false, + error: null, + }; + } + catch (error) { + console.error(`Could not parse input JSON: ${error.stack}`); + return { + program: this.programEditor.getValue(), + event: null, + is_jsonl: false, + error, + }; + } + return state; } disableJsonLinting() { @@ -168,6 +184,11 @@ export class VrlWebPlayground { if (input == null) { input = this.getState(); } + if (input.error) { + this.disableJsonLinting(); + this.outputEditor.setValue(input.error.stack); + return input; + } let res = this.run_vrl(input); console.log("[DEBUG::handleRunCode()] Printing out res: ", res); diff --git a/lib/vector-vrl/web-playground/public/package.json b/lib/vector-vrl/web-playground/public/package.json index e8bfd02f7d3ca..fbc6afde80a7f 100644 --- a/lib/vector-vrl/web-playground/public/package.json +++ b/lib/vector-vrl/web-playground/public/package.json @@ -8,7 +8,5 @@ ], "module": "vector_vrl_web_playground.js", "types": "vector_vrl_web_playground.d.ts", - "sideEffects": [ - "./snippets/*" - ] -} + "sideEffects": false +} \ No newline at end of file From cb87dc394bb3ecc028ee7689f838741304ff2b59 Mon Sep 17 00:00:00 2001 From: Pavlos Rontidis Date: Fri, 30 Jun 2023 17:30:08 -0400 Subject: [PATCH 2/2] better error message and manually edit generated files (newlines at eof are required) --- lib/vector-vrl/web-playground/public/.gitignore | 2 +- lib/vector-vrl/web-playground/public/index.js | 6 +++--- lib/vector-vrl/web-playground/public/package.json | 2 +- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/lib/vector-vrl/web-playground/public/.gitignore b/lib/vector-vrl/web-playground/public/.gitignore index f59ec20aabf58..de695ce7d35fc 100644 --- a/lib/vector-vrl/web-playground/public/.gitignore +++ b/lib/vector-vrl/web-playground/public/.gitignore @@ -1 +1 @@ -* \ No newline at end of file +vector_vrl_web_playground** diff --git a/lib/vector-vrl/web-playground/public/index.js b/lib/vector-vrl/web-playground/public/index.js index c30f64368e476..2a1d6aecb7ff5 100644 --- a/lib/vector-vrl/web-playground/public/index.js +++ b/lib/vector-vrl/web-playground/public/index.js @@ -114,12 +114,12 @@ export class VrlWebPlayground { }; } catch (error) { - console.error(`Could not parse input JSON: ${error.stack}`); + console.error(error); return { program: this.programEditor.getValue(), event: null, is_jsonl: false, - error, + error: `Could not parse JSON event:\n${editorValue}`, }; } return state; @@ -186,7 +186,7 @@ export class VrlWebPlayground { } if (input.error) { this.disableJsonLinting(); - this.outputEditor.setValue(input.error.stack); + this.outputEditor.setValue(input.error); return input; } diff --git a/lib/vector-vrl/web-playground/public/package.json b/lib/vector-vrl/web-playground/public/package.json index fbc6afde80a7f..fc6889020fde3 100644 --- a/lib/vector-vrl/web-playground/public/package.json +++ b/lib/vector-vrl/web-playground/public/package.json @@ -9,4 +9,4 @@ "module": "vector_vrl_web_playground.js", "types": "vector_vrl_web_playground.d.ts", "sideEffects": false -} \ No newline at end of file +}