From 3c697abc011c431f7c1d28be9b2739cadde23f37 Mon Sep 17 00:00:00 2001 From: Jacob Lee Date: Thu, 10 Oct 2024 21:14:56 -0700 Subject: [PATCH] feat(js): Validate that store values are RunTree instances (#1088) --- js/src/singletons/traceable.ts | 4 ++-- js/src/traceable.ts | 2 +- 2 files changed, 3 insertions(+), 3 deletions(-) diff --git a/js/src/singletons/traceable.ts b/js/src/singletons/traceable.ts index 0cdd1f936..9d1c617a4 100644 --- a/js/src/singletons/traceable.ts +++ b/js/src/singletons/traceable.ts @@ -1,4 +1,4 @@ -import { RunTree } from "../run_trees.js"; +import { isRunTree, RunTree } from "../run_trees.js"; import { TraceableFunction } from "./types.js"; interface AsyncLocalStorageInterface { @@ -47,7 +47,7 @@ export const AsyncLocalStorageProviderSingleton = */ export const getCurrentRunTree = () => { const runTree = AsyncLocalStorageProviderSingleton.getInstance().getStore(); - if (runTree === undefined) { + if (!isRunTree(runTree)) { throw new Error( [ "Could not get the current run tree.", diff --git a/js/src/traceable.ts b/js/src/traceable.ts index aa8137c1a..f4ceebda2 100644 --- a/js/src/traceable.ts +++ b/js/src/traceable.ts @@ -406,7 +406,7 @@ export function traceable any>( // Node.JS uses AsyncLocalStorage (ALS) and AsyncResource // to allow storing context const prevRunFromStore = asyncLocalStorage.getStore(); - if (prevRunFromStore) { + if (isRunTree(prevRunFromStore)) { return [ getTracingRunTree( prevRunFromStore.createChild(ensuredConfig),