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
+3
-2
@@ -118,8 +118,9 @@ npm treats versions as semver and semver forbids leading zeros.
|
||||
- **A node that needs the token it provides fails `createApp`** (GitHub #43). The graph check
|
||||
skipped a dependency whose producer was the node itself, so a step with `needs: ['user']` and
|
||||
`provides: ['user']` booted, and at request time read a value nobody had written. It now fails
|
||||
like any other missing dependency: `missing dependency: user needed by auth — it provides 'user'
|
||||
itself`. Since a token has one producer (GitHub #35), no other node can supply it; only a seeded
|
||||
as the cycle it is, naming 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.` Since a token has one producer (GitHub #35), no other node can supply it; only a seeded
|
||||
token (`req`, `params`) still satisfies a node's own need, because the node reads the seed.
|
||||
`overrides` do not exempt the node: they replace its runner after the graph is checked. To
|
||||
migrate, remove the token from the node's `needs`, or move the work that produces it into a
|
||||
|
||||
+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.`,
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
+1
-1
@@ -57,7 +57,7 @@ describe('one producer per token', () => {
|
||||
describe('self-dependency', () => {
|
||||
it('counts as missing when the token is not seeded', () => {
|
||||
expect(() => topoSort([node('auth', ['user'], ['user'])], [])).toThrow(
|
||||
/missing dependency: user needed by auth — it provides 'user' itself/,
|
||||
/cycle detected: auth -> auth \(it needs 'user', which only it provides\)/,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
@@ -88,9 +88,9 @@ describe('one producer per token', () => {
|
||||
// check that rejects the node runs before any override could.
|
||||
it('a node that needs the token it provides fails boot, with or without an override', () => {
|
||||
const loop = adds('loop', { kind: 'step', name: 'loop', needs: ['loop'], provides: ['loop'] });
|
||||
expect(() => createApp({ modules: [AppModule], plugins: [loop] })).toThrow(/missing dependency: loop needed by loop/);
|
||||
expect(() => createApp({ modules: [AppModule], plugins: [loop] })).toThrow(/cycle detected: loop -> loop/);
|
||||
expect(() => createApp({ modules: [AppModule], plugins: [loop], overrides: { loop: 1 } })).toThrow(
|
||||
/missing dependency: loop needed by loop/,
|
||||
/cycle detected: loop -> loop/,
|
||||
);
|
||||
});
|
||||
|
||||
|
||||
Reference in new issue
Block a user