refactor(migrations): gracefully handle metadata parsing errors in signal migration (#58413)

In 1P, we saw that a type of a target wasn't resolvable, referenced in a
`hostBindings#directive` field. This breaks the entire pipeline; so we
should handle gracefully but report an error.

Worst case scenario here is that we would miss some references to the
given directive/component. This is acceptable and we can continue
investigation why that given target was broken; especially since the
file was part of the target inputs- but seemingly not in the `tsconfig`.

PR Close #58413
This commit is contained in:
Paul Gschwendtner 2024-10-29 16:42:25 +00:00 committed by Alex Rickabaugh
parent 7f10343659
commit 0d955f67ed

View file

@ -14,6 +14,7 @@ import {FatalDiagnosticError} from '@angular/compiler-cli/src/ngtsc/diagnostics'
import {Reference, ReferenceEmitter} from '@angular/compiler-cli/src/ngtsc/imports';
import {
DecoratorInputTransform,
DirectiveMeta,
DtsMetadataReader,
InputMapping,
} from '@angular/compiler-cli/src/ngtsc/metadata';
@ -74,9 +75,20 @@ function extractDtsInput(node: ts.Node, metadataReader: DtsMetadataReader): Extr
return null;
}
const directiveMetadata = metadataReader.getDirectiveMetadata(
new Reference(node.parent as ClassDeclaration),
);
let directiveMetadata: DirectiveMeta | null = null;
// Getting directive metadata can throw errors when e.g. types referenced
// in the `.d.ts` aren't resolvable. This seems to be unexpected and shouldn't
// result in the entire migration to be failing.
try {
directiveMetadata = metadataReader.getDirectiveMetadata(
new Reference(node.parent as ClassDeclaration),
);
} catch (e) {
console.error('Unexpected error. Gracefully ignoring.');
console.error('Could not parse directive metadata:', e);
return null;
}
const inputMapping = directiveMetadata?.inputs.getByClassPropertyName(node.name.text);
// Signal inputs are never tracked and migrated.