refactor(devtools): Use the same error message as the signal custom formatter for signal errors

When signals throw errors on read, the devtools will show the same error message as the signal custom formatter.
We also don't log errors anymore to the console as those might be surprising to see as errors and are buggy behavior of the devtools.
This commit is contained in:
Matthieu Riegler 2025-11-25 21:46:53 +02:00 committed by Kirill Cherkashin
parent 5b720aa2eb
commit a0930e166c
2 changed files with 2 additions and 3 deletions

View file

@ -180,13 +180,13 @@ const getPreview = (propData: TerminalType | CompositeType, isGetterOrSetter: bo
if (propData.containerType === 'ReadonlySignal') {
const {error, value} = safelyReadSignalValue(propData.prop);
if (error) {
return 'ERROR: Could not read signal value. See console for details.';
return `Signal(⚠️ Error)${error.message ? `: ${error.message}` : ''}`;
}
return `Readonly Signal(${typeToDescriptorPreview[propData.type](value)})`;
} else if (propData.containerType === 'WritableSignal') {
const {error, value} = safelyReadSignalValue(propData.prop);
if (error) {
return 'ERROR: Could not read signal value. See console for details.';
return `Signal(⚠️ Error)${error.message ? `: ${error.message}` : ''}`;
}
return `Signal(${typeToDescriptorPreview[propData.type](value)})`;
}

View file

@ -50,7 +50,6 @@ export function safelyReadSignalValue(signal: any): {error?: Error; value?: any}
const value = signal();
return {error: undefined, value};
} catch (error) {
console.error('[Angular DevTools]: Error reading signal value:', error);
return {error: error as Error, value: undefined};
}
}