66 * found in the LICENSE file at https://angular.dev/license
77 */
88
9- import { computed , Signal , untracked , WritableSignal } from '@angular/core' ;
9+ import {
10+ computed ,
11+ Signal ,
12+ untracked ,
13+ WritableSignal ,
14+ ɵRuntimeError as RuntimeError ,
15+ } from '@angular/core' ;
16+ import { SignalFormsErrorCode } from '../errors' ;
1017import { AbstractControl } from '@angular/forms' ;
1118import {
1219 FieldContext ,
@@ -65,7 +72,10 @@ export class FieldNodeContext implements FieldContext<unknown> {
6572 stepsRemaining -- ;
6673 field = field . structure . parent ;
6774 if ( field === undefined ) {
68- throw new Error ( 'Path is not part of this field tree.' ) ;
75+ throw new RuntimeError (
76+ SignalFormsErrorCode . PATH_NOT_IN_FIELD_TREE ,
77+ ngDevMode && 'Path is not part of this field tree.' ,
78+ ) ;
6979 }
7080 }
7181
@@ -74,11 +84,13 @@ export class FieldNodeContext implements FieldContext<unknown> {
7484 for ( let key of targetPathNode . keys ) {
7585 field = field . structure . getChild ( key ) ;
7686 if ( field === undefined ) {
77- throw new Error (
78- `Cannot resolve path .${ targetPathNode . keys . join ( '.' ) } relative to field ${ [
79- '<root>' ,
80- ...this . node . structure . pathKeys ( ) ,
81- ] . join ( '.' ) } .`,
87+ throw new RuntimeError (
88+ SignalFormsErrorCode . PATH_RESOLUTION_FAILED ,
89+ ngDevMode &&
90+ `Cannot resolve path .${ targetPathNode . keys . join ( '.' ) } relative to field ${ [
91+ '<root>' ,
92+ ...this . node . structure . pathKeys ( ) ,
93+ ] . join ( '.' ) } .`,
8294 ) ;
8395 }
8496 }
@@ -116,7 +128,10 @@ export class FieldNodeContext implements FieldContext<unknown> {
116128 const key = this . key ( ) ;
117129 // Assert that the parent is actually an array.
118130 if ( ! isArray ( untracked ( this . node . structure . parent ! . value ) ) ) {
119- throw new Error ( `RuntimeError: cannot access index, parent field is not an array` ) ;
131+ throw new RuntimeError (
132+ SignalFormsErrorCode . PARENT_NOT_ARRAY ,
133+ ngDevMode && 'Cannot access index, parent field is not an array.' ,
134+ ) ;
120135 }
121136 // Return the key as a number if we are indeed inside an array field.
122137 return Number ( key ) ;
@@ -128,8 +143,10 @@ export class FieldNodeContext implements FieldContext<unknown> {
128143 const result = this . resolve ( p ) ( ) . value ( ) ;
129144
130145 if ( result instanceof AbstractControl ) {
131- throw new Error (
132- `Tried to read an 'AbstractControl' value form a 'form()'. Did you mean to use 'compatForm()' instead?` ,
146+ throw new RuntimeError (
147+ SignalFormsErrorCode . ABSTRACT_CONTROL_IN_FORM ,
148+ ngDevMode &&
149+ `Tried to read an 'AbstractControl' value from a 'form()'. Did you mean to use 'compatForm()' instead?` ,
133150 ) ;
134151 }
135152 return result ;
0 commit comments