fix(graph): report a self-dependency as the cycle it is (GitHub #43)
A node that needs the token it provides is a cycle of one, so say so in the same words as every other cycle (`cycle detected: a -> a`), and name the token and the fix: cycle detected: auth -> auth (it needs 'user', which only it provides). Remove 'user' from its needs, or move the work that produces 'user' into a step it needs. "missing dependency … it provides it itself" pointed the reader at a missing producer, when the producer is there and the problem is the loop. Signed-off-by: Diego Resendez <diego.resendez@zero-oneit.com>
This commit is contained in:
4 files changed
+14
-9
No files matched your search
+8
-4
@@ -88,11 +88,15 @@ export function topoSort(nodes: GraphNode[], seedKeys: string[], note = ''): Gra
|
||||
|
||||
if (!producer) throw new Error(`missing dependency: ${key} needed by ${node.name}${note}`);
|
||||
|
||||
// A node is not its own dependency (GitHub #43): it would read a value nobody wrote yet.
|
||||
// `producers` already allows only one producer per token, so no other node can supply it;
|
||||
// only a seed makes the need real, and the seed case returned above.
|
||||
// A node that needs its own token is a cycle of one (GitHub #43): it would read a value nobody
|
||||
// wrote yet. `producers` already allows one producer per token, so no other node can supply
|
||||
// it; only a seed makes the need real, and the seed case continued above. Same wording as the
|
||||
// cycle check below, so both read as the one error they are.
|
||||
if (producer === node) {
|
||||
throw new Error(`missing dependency: ${key} needed by ${node.name} — it provides '${key}' itself${note}`);
|
||||
throw new Error(
|
||||
`cycle detected: ${node.name} -> ${node.name} (it needs '${key}', which only it provides)${note}. ` +
|
||||
`Remove '${key}' from its needs, or move the work that produces '${key}' into a step it needs.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
Reference in new issue
Block a user