From 7ac0b2a2acf4f85e55d78b2a40c537865c9df46f Mon Sep 17 00:00:00 2001 From: Jason Gwartz Date: Sat, 2 Mar 2024 17:55:28 +0000 Subject: [PATCH] close evaluator even if loadFromPath fails --- codegen/src/internal/TypescriptModule.pkl | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/codegen/src/internal/TypescriptModule.pkl b/codegen/src/internal/TypescriptModule.pkl index 6828795..d57ab7a 100644 --- a/codegen/src/internal/TypescriptModule.pkl +++ b/codegen/src/internal/TypescriptModule.pkl @@ -72,9 +72,12 @@ contents: String = new Listing { // LoadFromPath loads the pkl module at the given path and evaluates it into a \(moduleClass.name) export const loadFromPath = async (path: string): Promise<\(moduleClass.type.render(moduleClass.typescriptModule))> => { const evaluator = await pklTypescript.newEvaluator(pklTypescript.PreconfiguredOptions); - const result = await load(evaluator, pklTypescript.FileSource(path)); - evaluator.close() - return result + try { + const result = await load(evaluator, pklTypescript.FileSource(path)); + return result + } finally { + evaluator.close() + } }; export const load = (evaluator: pklTypescript.Evaluator, source: pklTypescript.ModuleSource): Promise<\(moduleClass.type.render(moduleClass.typescriptModule))> =>