Merge pull request #3477 from rkilpadi/main

Improve error message for missing type parameter
This commit is contained in:
Josh de Leeuw 2025-01-07 11:13:22 -05:00 committed by GitHub
commit 9d8597f8c7
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194
3 changed files with 21 additions and 1 deletions

View File

@ -0,0 +1,5 @@
---
"jspsych": patch
---
Add informative error message when a trial is missing the `type` parameter

View File

@ -36,6 +36,16 @@ describe("Trial", () => {
return trial;
};
it("throws an error upon construction when the `type` parameter or plugin info object is undefined", () => {
for (const description of [{}, { type: {} }] as TrialDescription[]) {
expect(
() => new Trial(dependencies, description, timeline)
).toThrowErrorMatchingInlineSnapshot(
"\"Plugin not recognized. Please provide a valid plugin using the 'type' parameter.\""
);
}
});
describe("run()", () => {
it("instantiates the corresponding plugin", async () => {
const trial = createTrial({ type: TestPlugin });

View File

@ -35,7 +35,12 @@ export class Trial extends TimelineNode {
this.trialObject = deepCopy(description);
this.pluginClass = this.getParameterValue("type", { evaluateFunctions: false });
this.pluginInfo = this.pluginClass["info"];
this.pluginInfo = this.pluginClass?.["info"];
if (!this.pluginInfo) {
throw new Error(
"Plugin not recognized. Please provide a valid plugin using the 'type' parameter."
);
}
if (!("version" in this.pluginInfo) && !("data" in this.pluginInfo)) {
console.warn(