Skip to content

Commit

Permalink
Show parseQuery error (gpuweb#2982)
Browse files Browse the repository at this point in the history
Some errors in parsing the query string were only showing
in the JavaScript console so that for a bad query the test page
would just show nothing. This is an attempt to try to surface
those errors to the page.
  • Loading branch information
greggman authored Sep 21, 2023
1 parent b1a998f commit c295665
Showing 1 changed file with 26 additions and 7 deletions.
33 changes: 26 additions & 7 deletions src/common/runtime/standalone.ts
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,7 @@ import { parseQuery } from '../internal/query/parseQuery.js';
import { TestQueryLevel } from '../internal/query/query.js';
import { TestTreeNode, TestSubtree, TestTreeLeaf, TestTree } from '../internal/tree.js';
import { setDefaultRequestAdapterOptions } from '../util/navigator_gpu.js';
import { assert, ErrorWithExtra, unreachable } from '../util/util.js';
import { ErrorWithExtra, unreachable } from '../util/util.js';

import {
kCTSOptionsInfo,
Expand Down Expand Up @@ -543,6 +543,14 @@ function createSearchQuery(queries: string[], params?: string) {
return `?${params}${params ? '&' : ''}${queries.map(q => 'q=' + q).join('&')}`;
}

/**
* Show an info message on the page.
* @param msg Message to show
*/
function showInfo(msg: string) {
$('#info')[0].textContent = msg;
}

void (async () => {
const loader = new DefaultTestFileLoader();

Expand Down Expand Up @@ -609,26 +617,37 @@ void (async () => {
};
addOptionsToPage(options, kStandaloneOptionsInfos);

assert(qs.length === 1, 'currently, there must be exactly one ?q=');
const rootQuery = parseQuery(qs[0]);
if (qs.length !== 1) {
showInfo('currently, there must be exactly one ?q=');
return;
}

let rootQuery;
try {
rootQuery = parseQuery(qs[0]);
} catch (e) {
showInfo((e as Error).toString());
return;
}

if (rootQuery.level > lastQueryLevelToExpand) {
lastQueryLevelToExpand = rootQuery.level;
}
loader.addEventListener('import', ev => {
$('#info')[0].textContent = `loading: ${ev.data.url}`;
showInfo(`loading: ${ev.data.url}`);
});
loader.addEventListener('imported', ev => {
$('#info')[0].textContent = `imported: ${ev.data.url}`;
showInfo(`imported: ${ev.data.url}`);
});
loader.addEventListener('finish', () => {
$('#info')[0].textContent = '';
showInfo('');
});

let tree;
try {
tree = await loader.loadTree(rootQuery);
} catch (err) {
$('#info')[0].textContent = (err as Error).toString();
showInfo((err as Error).toString());
return;
}

Expand Down

0 comments on commit c295665

Please sign in to comment.