Skip to content

Commit

Permalink
SchemaRetreiver: typecheck dataset examples individually (#324)
Browse files Browse the repository at this point in the history
In certain cases, the dataset can fail to typecheck as a whole
because there are examples with newer functions or wrong parameters.
This can occur if a device has been updated recently (in the last
3 hours), or can occur for a builtin device if Genie or the platform
layers have not been updated yet.
In that case, we should ignore and log the error, and let as many
examples through as we can.

Fixes stanford-oval/thingpedia-common-devices#286
and will probably help with stanford-oval/almond-gnome#40
  • Loading branch information
gcampax authored Mar 7, 2021
1 parent 16f505f commit ab4e054
Showing 1 changed file with 11 additions and 1 deletion.
12 changes: 11 additions & 1 deletion lib/schema.ts
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,6 @@ export default class SchemaRetriever {
this._classCache.dataset.set(kind, result[kind] = new Dataset(null, kind, []));
} else {
const parsed = Grammar.parse(code) as Library;
await parsed.typecheck(this, true);

const examples = new Map<string, Example[]>();

Expand All @@ -554,6 +553,17 @@ export default class SchemaRetriever {
// on disk
for (const dataset of parsed.datasets) {
for (const example of dataset.examples) {
// typecheck each example individually, and ignore those that do not
// typecheck
// this can occur if the dataset we retrieved from Thingpedia is newer
// than the cached manifest and includes new functions or a parameter change
try {
await example.typecheck(this, true);
} catch(e) {
console.log(`Failed to load dataset example ${example.id}: ${e.message}`);
continue;
}

const devices = new Set<string>();
for (const [, prim] of example.iteratePrimitives(false))
devices.add(prim.selector.kind);
Expand Down

0 comments on commit ab4e054

Please sign in to comment.