From f592839d4710836b9dc98baa6fbff01d0f442bfb Mon Sep 17 00:00:00 2001 From: Sebastian Malton Date: Thu, 1 Sep 2022 11:36:45 -0400 Subject: [PATCH] Improve error message for mismatched runnables Signed-off-by: Sebastian Malton --- src/common/runnable/run-many-for.test.ts | 2 +- src/common/runnable/run-many-for.ts | 2 +- src/common/runnable/run-many-sync-for.test.ts | 2 +- src/common/runnable/run-many-sync-for.ts | 2 +- src/common/runnable/throw-with-incorrect-hierarchy-for.ts | 4 ++-- 5 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/common/runnable/run-many-for.test.ts b/src/common/runnable/run-many-for.test.ts index d2ec2d2513..c73f448dd2 100644 --- a/src/common/runnable/run-many-for.test.ts +++ b/src/common/runnable/run-many-for.test.ts @@ -223,7 +223,7 @@ describe("runManyFor", () => { ); return expect(() => runMany()).rejects.toThrow( - "Tried to run runnable after other runnable which does not same injection token.", + 'Tried to run runnable "some-runnable-1" after the runnable "some-runnable-2" which does not share the "some-injection-token" injection token.', ); }); diff --git a/src/common/runnable/run-many-for.ts b/src/common/runnable/run-many-for.ts index 2563b5416d..478d7f84a4 100644 --- a/src/common/runnable/run-many-for.ts +++ b/src/common/runnable/run-many-for.ts @@ -26,7 +26,7 @@ export function runManyFor(di: DiContainerForInjection): RunMany { return (injectionToken) => async (parameter) => { const allRunnables = di.injectMany(injectionToken); - const throwWithIncorrectHierarchy = throwWithIncorrectHierarchyFor(allRunnables); + const throwWithIncorrectHierarchy = throwWithIncorrectHierarchyFor((injectionToken as any).id, allRunnables); const recursedRun = async ( runAfterRunnable: Runnable | undefined = undefined, diff --git a/src/common/runnable/run-many-sync-for.test.ts b/src/common/runnable/run-many-sync-for.test.ts index e843806607..43d2832663 100644 --- a/src/common/runnable/run-many-sync-for.test.ts +++ b/src/common/runnable/run-many-sync-for.test.ts @@ -152,7 +152,7 @@ describe("runManySyncFor", () => { ); return expect(() => runMany()).rejects.toThrow( - "Tried to run runnable after other runnable which does not same injection token.", + 'Tried to run runnable "some-runnable-1" after the runnable "some-runnable-2" which does not share the "some-injection-token" injection token.', ); }); diff --git a/src/common/runnable/run-many-sync-for.ts b/src/common/runnable/run-many-sync-for.ts index fa658f052a..1d3dcec2c5 100644 --- a/src/common/runnable/run-many-sync-for.ts +++ b/src/common/runnable/run-many-sync-for.ts @@ -24,7 +24,7 @@ export function runManySyncFor(di: DiContainerForInjection): RunManySync { return (injectionToken) => async (parameter) => { const allRunnables = di.injectMany(injectionToken); - const throwWithIncorrectHierarchy = throwWithIncorrectHierarchyFor(allRunnables); + const throwWithIncorrectHierarchy = throwWithIncorrectHierarchyFor((injectionToken as any).id, allRunnables); const recursedRun = ( runAfterRunnable: RunnableSync | undefined = undefined, diff --git a/src/common/runnable/throw-with-incorrect-hierarchy-for.ts b/src/common/runnable/throw-with-incorrect-hierarchy-for.ts index 998b37f572..bddf8037c2 100644 --- a/src/common/runnable/throw-with-incorrect-hierarchy-for.ts +++ b/src/common/runnable/throw-with-incorrect-hierarchy-for.ts @@ -5,10 +5,10 @@ import type { Runnable } from "./run-many-for"; import type { RunnableSync } from "./run-many-sync-for"; -export const throwWithIncorrectHierarchyFor = (allRunnables: Runnable[] | RunnableSync[]) => ( +export const throwWithIncorrectHierarchyFor = (injectionTokenId: string, allRunnables: Runnable[] | RunnableSync[]) => ( (runnable: Runnable | RunnableSync) => { if (runnable.runAfter && !allRunnables.includes(runnable.runAfter)) { - throw new Error(`Tried to run runnable "${runnable.id}" after the runnable "${runnable.runAfter.id}" which does not same injection token.`); + throw new Error(`Tried to run runnable "${runnable.id}" after the runnable "${runnable.runAfter.id}" which does not share the "${injectionTokenId}" injection token.`); } } );