diff --git a/src/app/index.ts b/src/app/index.ts index fdacab7..b486129 100644 --- a/src/app/index.ts +++ b/src/app/index.ts @@ -221,7 +221,7 @@ export function createApp(opts: { let remoteRoutes: RouteDef[] = []; const meshLinks: Link[] = []; - const finalize = (missingNote?: (key: string) => string): void => { + const finalize = (missingNote?: string): void => { ({ orderedProviders, orderedSteps } = finalizeGraph(registry, logger, opts.warnGraphDepth, missingNote)); booted = true; }; @@ -244,7 +244,7 @@ export function createApp(opts: { // Without this the error is `missing dependency: auth needed by getUser` and says nothing // about the teapot that was away — which is the actual cause every time it is the cause. const meshNote = spliced.absent.length - ? () => ` — these teapots did not connect, so their exports are absent: ${spliced.absent.join(', ')}` + ? ` — these teapots did not connect, so their exports are absent: ${spliced.absent.join(', ')}` : undefined; finalize(meshNote); } @@ -667,7 +667,7 @@ function finalizeGraph( registry: Registry, logger: Logger, warnDepth: number | false = DEEP_GRAPH_WARN, - missingNote?: (key: string) => string, + missingNote?: string, ): { orderedProviders: GraphNode[]; orderedSteps: GraphNode[] } { const { providerNodes, stepNodes, routePlans } = registry; const ordered = topoSort([...providerNodes, ...stepNodes], ['req', 'params'], missingNote); @@ -711,7 +711,7 @@ function assertNeedsSatisfiable( routePlans: RoutePlan[], providerNodes: GraphNode[], stepNodes: GraphNode[], - missingNote?: (key: string) => string, + missingNote?: string, ): void { const producedKeys = new Set([ ...providerNodes.flatMap((node) => node.provides), @@ -744,7 +744,7 @@ function assertNeedsSatisfiable( const scope = missingNote ? 'local or connected mesh' : 'local or mesh'; throw new Error( `handler '${plan.handlerName}' needs '${need}' but nothing (${scope}) provides it` + - `${hint ? ` — did you mean '${hint}'?` : ''}${missingNote?.(need) ?? ''}`, + `${hint ? ` — did you mean '${hint}'?` : ''}${missingNote ?? ''}`, ); } } diff --git a/src/graph.ts b/src/graph.ts index 66c8d4d..14fd57b 100644 --- a/src/graph.ts +++ b/src/graph.ts @@ -43,7 +43,7 @@ export interface GraphNode { } /** Orders nodes so every dependency precedes its dependents; throws on missing keys or cycles. */ -export function topoSort(nodes: GraphNode[], seedKeys: string[], note?: (key: string) => string): GraphNode[] { +export function topoSort(nodes: GraphNode[], seedKeys: string[], note = ''): GraphNode[] { const producedBy = new Map(); for (const node of nodes) for (const key of node.provides) producedBy.set(key, node); @@ -51,7 +51,7 @@ export function topoSort(nodes: GraphNode[], seedKeys: string[], note?: (key: st for (const node of nodes) { for (const key of node.needs) { if (!seedKeys.includes(key) && !producedBy.has(key)) { - throw new Error(`missing dependency: ${key} needed by ${node.name}${note?.(key) ?? ''}`); + throw new Error(`missing dependency: ${key} needed by ${node.name}${note}`); } } }