Skip to content

Commit 8953e45

Browse files
crisbetopkozlowski-opensource
authored andcommitted
fix(core): include input name in error message (#60404)
Includes either the `debugName` or alias of an input in the error message about a value not being available. Fixes #60199. PR Close #60404
1 parent 1668b9f commit 8953e45

File tree

2 files changed

+34
-4
lines changed

2 files changed

+34
-4
lines changed

packages/core/src/authoring/input/input_signal.ts

Lines changed: 6 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,12 @@ export function createInputSignal<T, TransformT>(
127127
producerAccessed(node);
128128

129129
if (node.value === REQUIRED_UNSET_VALUE) {
130-
throw new RuntimeError(
131-
RuntimeErrorCode.REQUIRED_INPUT_NO_VALUE,
132-
ngDevMode && 'Input is required but no value is available yet.',
133-
);
130+
let message: string | null = null;
131+
if (ngDevMode) {
132+
const name = options?.debugName ?? options?.alias;
133+
message = `Input${name ? ` "${name}"` : ''} is required but no value is available yet.`;
134+
}
135+
throw new RuntimeError(RuntimeErrorCode.REQUIRED_INPUT_NO_VALUE, message);
134136
}
135137

136138
return node.value;

packages/core/test/authoring/input_signal_spec.ts

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,6 +78,34 @@ describe('input signal', () => {
7878
});
7979
});
8080

81+
it('should include debugName in required inputs error message, if available', () => {
82+
TestBed.runInInjectionContext(() => {
83+
const signal = input.required({debugName: 'mySignal'});
84+
const node = signal[SIGNAL];
85+
86+
expect(() => signal()).toThrowError(
87+
/Input "mySignal" is required but no value is available yet\./,
88+
);
89+
90+
node.applyValueToInputSignal(node, 1);
91+
expect(signal()).toBe(1);
92+
});
93+
});
94+
95+
it('should include alias in required inputs error message, if available', () => {
96+
TestBed.runInInjectionContext(() => {
97+
const signal = input.required({alias: 'alias'});
98+
const node = signal[SIGNAL];
99+
100+
expect(() => signal()).toThrowError(
101+
/Input "alias" is required but no value is available yet\./,
102+
);
103+
104+
node.applyValueToInputSignal(node, 1);
105+
expect(signal()).toBe(1);
106+
});
107+
});
108+
81109
it('should throw if a `computed` depends on an uninitialized required input', () => {
82110
TestBed.runInInjectionContext(() => {
83111
const signal = input.required<number>();

0 commit comments

Comments
 (0)