8000 fix(core): include input name in error message (#60404) · angular/angular@0615ffb · GitHub
[go: up one dir, main page]

Skip to content

Commit 0615ffb

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 acaadca commit 0615ffb

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
@@ -85,6 +85,34 @@ describe('input signal', () => {
8585
});
8686
});
8787

88+
it('should include debugName in required inputs error message, if available', () => {
89+
TestBed.runInInjectionContext(() => {
90+
const signal = input.required({debugName: 'mySignal'});
91+
const node = signal[SIGNAL];
92+
93+
expect(() => signal()).toThrowError(
94+
/Input "mySignal" is required but no value is available yet\./,
95+
);
96+
97+
node.applyValueToInputSignal(node, 1);
98+
expect(signal()).toBe(1);
99+
});
100+
});
101+
102+
it('should include alias in required inputs error message, if available', () => {
103+
TestBed.runInInjectionContext(() => {
104+
const signal = input.required({alias: 'alias'});
105+
const node = signal[SIGNAL];
106+
107+
expect(() => signal()).toThrowError(
108+
/Input "alias" is required but no value is available yet\./,
109+
);
110+
111+
node.applyValueToInputSignal(node, 1);
112+
expect(signal()).toBe(1);
113+
});
114+
});
115+
88116
it('should throw if a `computed` depends on an uninitialized required input', () => {
89117
TestBed.runInInjectionContext(() => {
90118
const signal = input.required<number>();

0 commit comments

Comments
 (0)
0