fix(mesh): name the absent teapot in the route-level missing-need error too
assertNeedsSatisfiable is a separate check from topoSort, so it didn't get the note threaded into finalizeGraph -- a handler-level @needs against an absent teapot's token read as a typo or a forgotten export: true, which is worse than the pre-task behavior (the boot used to throw naming the teapot). Thread missingNote through and soften "local or mesh" to "local or connected mesh" when it's set, so the message doesn't claim a search that never happened. Also tightens two test assertions that only passed because "mesh" happened to appear inside the unrelated "(local or mesh)" wording, and removes adopt()'s now-fully-unused attempt parameter in mesh/link.ts instead of leaving it underscored. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
3 files changed
+47
-9
No files matched your search
+13
-3
@@ -695,12 +695,17 @@ function finalizeGraph(
|
||||
}
|
||||
}
|
||||
|
||||
assertNeedsSatisfiable(routePlans, providerNodes, stepNodes);
|
||||
assertNeedsSatisfiable(routePlans, providerNodes, stepNodes, missingNote);
|
||||
return { orderedProviders, orderedSteps };
|
||||
}
|
||||
|
||||
/** Throws if any route needs a key that nothing (local or mesh) provides, suggesting the nearest match. */
|
||||
function assertNeedsSatisfiable(routePlans: RoutePlan[], providerNodes: GraphNode[], stepNodes: GraphNode[]): void {
|
||||
function assertNeedsSatisfiable(
|
||||
routePlans: RoutePlan[],
|
||||
providerNodes: GraphNode[],
|
||||
stepNodes: GraphNode[],
|
||||
missingNote?: (key: string) => string,
|
||||
): void {
|
||||
const producedKeys = new Set<string>([
|
||||
...providerNodes.flatMap((node) => node.provides),
|
||||
...stepNodes.flatMap((node) => node.provides),
|
||||
@@ -726,8 +731,13 @@ function assertNeedsSatisfiable(routePlans: RoutePlan[], providerNodes: GraphNod
|
||||
}
|
||||
|
||||
const hint = nearest(need, allowed);
|
||||
// "local or mesh" claims the mesh was consulted and came up empty — true only when every
|
||||
// teapot connected. When one didn't, say "connected mesh" instead so the message doesn't
|
||||
// assert a search that never happened, and let missingNote name which teapots were away.
|
||||
const scope = missingNote ? 'local or connected mesh' : 'local or mesh';
|
||||
throw new Error(
|
||||
`handler '${plan.handlerName}' needs '${need}' but nothing (local or mesh) provides it${hint ? ` — did you mean '${hint}'?` : ''}`,
|
||||
`handler '${plan.handlerName}' needs '${need}' but nothing (${scope}) provides it` +
|
||||
`${hint ? ` — did you mean '${hint}'?` : ''}${missingNote?.(need) ?? ''}`,
|
||||
);
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user