Skip to content

Commit 8519cb1

Browse files
authored
fix: propagate and display invalid JSON errors in VRL web playground (#17826)
<!-- **Your PR title must conform to the conventional commit spec!** <type>(<scope>)!: <description> * `type` = chore, enhancement, feat, fix, docs * `!` = OPTIONAL: signals a breaking change * `scope` = Optional when `type` is "chore" or "docs", available scopes https://github.com/vectordotdev/vector/blob/master/.github/semantic.yml#L20 * `description` = short description of the change Examples: * enhancement(file source): Add `sort` option to sort discovered files * feat(new source): Initial `statsd` source * fix(file source): Fix a bug discovering new files * chore(external docs): Clarify `batch_size` option --> closes: #17445 Note that `wasm-pack build` modified some previously generated files. Created #17827. Example: ![image](https://github.com/vectordotdev/vector/assets/1138161/4fd0b825-8e1b-4466-9c90-5ab8705ad0e8)
1 parent bc86222 commit 8519cb1

File tree

3 files changed

+37
-17
lines changed

3 files changed

+37
-17
lines changed

lib/vector-vrl/web-playground/public/README.md

+10-9
Original file line numberDiff line numberDiff line change
@@ -53,15 +53,16 @@ Some functions of VRL are not supported or don't work as expected at the
5353
moment due to WASM limitations with some Rust crates, in
5454
the future we will modify the functions so that they are supported.
5555

56-
List of functions that aren't supported at the moment:
57-
58-
- `log()`
59-
- `decrypt()`
60-
- `encrypt()`
61-
- `get_hostname()`
62-
- `parse_groks()`
63-
- `random_bytes()`
64-
- `reverse_dns()`
56+
List of functions that aren't supported at the moment. All of them exist,
57+
but they will either error (enrichment functions) or abort (all the others) at runtime.
58+
59+
- `log`
60+
- `get_hostname`
61+
- `parse_grok`
62+
- `parse_groks`
63+
- `reverse_dns`
64+
- `find_enrichment_table_records`
65+
- `get_enrichment_table_record`
6566

6667
Functions from VRL stdlib that are currently not supported can be found
6768
with this [issue filter][vrl-wasm-unsupported-filter]

lib/vector-vrl/web-playground/public/index.js

+26-5
Original file line numberDiff line numberDiff line change
@@ -100,13 +100,29 @@ export class VrlWebPlayground {
100100
program: this.programEditor.getValue(),
101101
event: this.eventEditor.getModel().getLinesContent().join("\n"),
102102
is_jsonl: true,
103+
error: null,
103104
};
104105
}
105-
return {
106-
program: this.programEditor.getValue(),
107-
event: JSON.parse((this.eventEditor.getValue().length == 0) ? "{}" : this.eventEditor.getValue()),
108-
is_jsonl: false,
109-
};
106+
107+
const editorValue = this.eventEditor.getValue();
108+
try {
109+
return {
110+
program: this.programEditor.getValue(),
111+
event: JSON.parse((editorValue.length === 0) ? "{}" : editorValue),
112+
is_jsonl: false,
113+
error: null,
114+
};
115+
}
116+
catch (error) {
117+
console.error(error);
118+
return {
119+
program: this.programEditor.getValue(),
120+
event: null,
121+
is_jsonl: false,
122+
error: `Could not parse JSON event:\n${editorValue}`,
123+
};
124+
}
125+
return state;
110126
}
111127

112128
disableJsonLinting() {
@@ -168,6 +184,11 @@ export class VrlWebPlayground {
168184
if (input == null) {
169185
input = this.getState();
170186
}
187+
if (input.error) {
188+
this.disableJsonLinting();
189+
this.outputEditor.setValue(input.error);
190+
return input;
191+
}
171192

172193
let res = this.run_vrl(input);
173194
console.log("[DEBUG::handleRunCode()] Printing out res: ", res);

lib/vector-vrl/web-playground/public/package.json

+1-3
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,5 @@
88
],
99
"module": "vector_vrl_web_playground.js",
1010
"types": "vector_vrl_web_playground.d.ts",
11-
"sideEffects": [
12-
"./snippets/*"
13-
]
11+
"sideEffects": false
1412
}

0 commit comments

Comments
 (0)