Skip to content

Commit ae82ad5

Browse files
committed
feat: more error details for manuall query
Manual Restquery edit shows now directly the failing parser error with a hint to the line/char failing.
1 parent acc4218 commit ae82ad5

File tree

1 file changed

+12
-3
lines changed

1 file changed

+12
-3
lines changed

src/webview/src/components/dltRestQueryManual.js

+12-3
Original file line numberDiff line numberDiff line change
@@ -67,10 +67,19 @@ const rqUriEncode = (rq) => {
6767
JSON5.parse(commandParam);
6868
const commandParamEncoded = encodeURIComponent(formatJson5(commandParam));
6969
toRet += `${command}=${commandParamEncoded}`;
70-
} catch {
70+
} catch (e) {
7171
// if its a simple string then it's ok
7272
if (commandParam.includes('{') || commandParam.includes('[') || commandParam.includes('"')) {
73-
toRet += `&\n<cannot parse: \n'${command}=${commandParam}'\n as JSON5>`;
73+
// try to parse the location: .... at x:y as (line, col)
74+
const matches = /at (\d+):(\d+)$/.exec(e);
75+
if (matches) {
76+
const line = matches[1];
77+
const col = matches[2];
78+
const failLine = commandParam.split(/\r?\n/)[line - 1];
79+
toRet += `&\n<${e}:\n${failLine}\n${col > 0 ? ('-'.repeat(col - 1) + '^') : '^'}\n parsing JSON5 at \n'${command}=${commandParam}'\n>`;
80+
} else {
81+
toRet += `&\n<cannot parse: \n'${command}=${commandParam}'\n as JSON5 due to '${e}'>`;
82+
}
7483
ok = false;
7584
} else {
7685
toRet += `${command}=${commandParam}`;
@@ -151,7 +160,7 @@ export default function DLTRestQueryManualDialog(props) {
151160
error.length > 0 && <div>
152161
<ErrorIcon />
153162
<TextField error label="Error:" name="DLT rest query error" margin="dense" id={'description-field-rest-query-error'}
154-
InputLabelProps={{ shrink: true, }} fullWidth multiline value={error}
163+
InputLabelProps={{ shrink: true, }} fullWidth multiline value={error} InputProps={{ style: { fontFamily: 'monospace' } }}
155164
></TextField>
156165
</div>
157166
}

0 commit comments

Comments
 (0)