@@ -71,6 +71,8 @@ export interface InputFieldDeclaration {
7171 * A collection of the input field arguments.
7272 */
7373 argumentContainer : InputFieldArgumentContainer ;
74+
75+ error ?: Error | string ;
7476}
7577
7678export interface Template {
@@ -98,36 +100,43 @@ export class InputFieldDeclarationParser {
98100 // field type check
99101 fullDeclaration . inputFieldType = InputFieldDeclarationParser . getInputFieldType ( fullDeclaration . inputFieldType ) ;
100102
101- // template check:
102- let useTemplate : boolean = isTruthy ( templateName ) ;
103- if ( useTemplate ) {
104- InputFieldDeclarationParser . applyTemplate ( fullDeclaration , templateName ) ;
105- }
103+ try {
104+ // template check:
105+ let useTemplate : boolean = isTruthy ( templateName ) ;
106+ if ( useTemplate ) {
107+ InputFieldDeclarationParser . applyTemplate ( fullDeclaration , templateName ) ;
108+ }
106109
107- if ( fullDeclaration . inputFieldType === InputFieldType . INVALID ) {
108- throw new MetaBindParsingError ( `unknown input field type` ) ;
109- }
110+ if ( fullDeclaration . inputFieldType === InputFieldType . INVALID ) {
111+ throw new MetaBindParsingError ( `unknown input field type` ) ;
112+ }
110113
111- // arguments check:
112- fullDeclaration . argumentContainer = new InputFieldArgumentContainer ( ) ;
113- if ( inputFieldArguments ) {
114- for ( const inputFieldArgumentIdentifier in Object . keys ( inputFieldArguments ) ) {
115- const inputFieldArgument : AbstractInputFieldArgument = InputFieldArgumentFactory . createInputFieldArgument ( inputFieldArgumentIdentifier ) ;
114+ // arguments check:
115+ fullDeclaration . argumentContainer = new InputFieldArgumentContainer ( ) ;
116+ if ( inputFieldArguments ) {
117+ for ( const inputFieldArgumentIdentifier in Object . keys ( inputFieldArguments ) ) {
118+ const inputFieldArgument : AbstractInputFieldArgument = InputFieldArgumentFactory . createInputFieldArgument ( inputFieldArgumentIdentifier ) ;
116119
117- if ( ! inputFieldArgument . isAllowed ( fullDeclaration . inputFieldType ) ) {
118- throw new MetaBindParsingError (
119- `argument \'${ inputFieldArgumentIdentifier } \' is only applicable to ${ inputFieldArgument . getAllowedInputFieldsAsString ( ) } input fields`
120- ) ;
121- }
120+ if ( ! inputFieldArgument . isAllowed ( fullDeclaration . inputFieldType ) ) {
121+ throw new MetaBindParsingError (
122+ `argument \'${ inputFieldArgumentIdentifier } \' is only applicable to ${ inputFieldArgument . getAllowedInputFieldsAsString ( ) } input fields`
123+ ) ;
124+ }
125+
126+ if ( inputFieldArgument . requiresValue ) {
127+ inputFieldArgument . parseValue ( ( inputFieldArguments as Record < InputFieldArgumentType , string > ) [ inputFieldArgumentIdentifier as InputFieldArgumentType ] ) ;
128+ }
122129
123- if ( inputFieldArgument . requiresValue ) {
124- inputFieldArgument . parseValue ( ( inputFieldArguments as Record < InputFieldArgumentType , string > ) [ inputFieldArgumentIdentifier as InputFieldArgumentType ] ) ;
130+ fullDeclaration . argumentContainer . add ( inputFieldArgument ) ;
125131 }
126132
127- fullDeclaration . argumentContainer . add ( inputFieldArgument ) ;
133+ fullDeclaration . argumentContainer . validate ( ) ;
134+ }
135+ } catch ( e ) {
136+ if ( e instanceof Error ) {
137+ fullDeclaration . error = e ;
138+ console . warn ( e ) ;
128139 }
129-
130- fullDeclaration . argumentContainer . validate ( ) ;
131140 }
132141
133142 return fullDeclaration ;
@@ -136,57 +145,64 @@ export class InputFieldDeclarationParser {
136145 static parseString ( fullDeclaration : string ) : InputFieldDeclaration {
137146 let inputFieldDeclaration : InputFieldDeclaration = { } as InputFieldDeclaration ;
138147
139- let useTemplate = false ;
140- let templateName = '' ;
141-
142- // declaration
143- inputFieldDeclaration . fullDeclaration = fullDeclaration ;
144- const temp = ParserUtils . getInBetween ( fullDeclaration , InputFieldDeclarationParser . squareBracesPair ) ;
145- if ( Array . isArray ( temp ) ) {
146- if ( temp . length === 2 ) {
147- useTemplate = true ;
148- templateName = temp [ 0 ] ;
149- inputFieldDeclaration . declaration = temp [ 1 ] ;
148+ try {
149+ let useTemplate = false ;
150+ let templateName = '' ;
151+
152+ // declaration
153+ inputFieldDeclaration . fullDeclaration = fullDeclaration ;
154+ const temp = ParserUtils . getInBetween ( fullDeclaration , InputFieldDeclarationParser . squareBracesPair ) ;
155+ if ( Array . isArray ( temp ) ) {
156+ if ( temp . length === 2 ) {
157+ useTemplate = true ;
158+ templateName = temp [ 0 ] ;
159+ inputFieldDeclaration . declaration = temp [ 1 ] ;
160+ } else {
161+ throw new MetaBindParsingError ( 'invalid input field declaration' ) ;
162+ }
150163 } else {
151- throw new MetaBindParsingError ( 'invalid input field declaration' ) ;
164+ inputFieldDeclaration . declaration = temp ;
152165 }
153- } else {
154- inputFieldDeclaration . declaration = temp ;
155- }
156166
157- // declaration parts
158- const declarationParts : string [ ] = ParserUtils . split ( inputFieldDeclaration . declaration , ':' , InputFieldDeclarationParser . squareBracesPair ) ;
159-
160- // bind target
161- inputFieldDeclaration . bindTarget = declarationParts [ 1 ] ?? '' ;
162- inputFieldDeclaration . isBound = isTruthy ( inputFieldDeclaration . bindTarget ) ;
163-
164- // input field type and arguments
165- const inputFieldTypeWithArguments : string = declarationParts [ 0 ] ;
166- if ( inputFieldTypeWithArguments ) {
167- // input field type
168- const inputFieldTypeString = ParserUtils . removeInBetween ( inputFieldTypeWithArguments , InputFieldDeclarationParser . roundBracesPair ) ;
169- inputFieldDeclaration . inputFieldType = InputFieldDeclarationParser . getInputFieldType ( inputFieldTypeString ) ;
170-
171- // arguments
172- const inputFieldArgumentsString : string = ParserUtils . getInBetween ( inputFieldTypeWithArguments , InputFieldDeclarationParser . roundBracesPair ) as string ;
173- // console.log(inputFieldArgumentsString);
174- if ( inputFieldArgumentsString ) {
175- inputFieldDeclaration . argumentContainer = InputFieldDeclarationParser . parseArguments ( inputFieldArgumentsString , inputFieldDeclaration . inputFieldType ) ;
167+ // declaration parts
168+ const declarationParts : string [ ] = ParserUtils . split ( inputFieldDeclaration . declaration , ':' , InputFieldDeclarationParser . squareBracesPair ) ;
169+
170+ // bind target
171+ inputFieldDeclaration . bindTarget = declarationParts [ 1 ] ?? '' ;
172+ inputFieldDeclaration . isBound = isTruthy ( inputFieldDeclaration . bindTarget ) ;
173+
174+ // input field type and arguments
175+ const inputFieldTypeWithArguments : string = declarationParts [ 0 ] ;
176+ if ( inputFieldTypeWithArguments ) {
177+ // input field type
178+ const inputFieldTypeString = ParserUtils . removeInBetween ( inputFieldTypeWithArguments , InputFieldDeclarationParser . roundBracesPair ) ;
179+ inputFieldDeclaration . inputFieldType = InputFieldDeclarationParser . getInputFieldType ( inputFieldTypeString ) ;
180+
181+ // arguments
182+ const inputFieldArgumentsString : string = ParserUtils . getInBetween ( inputFieldTypeWithArguments , InputFieldDeclarationParser . roundBracesPair ) as string ;
183+ // console.log(inputFieldArgumentsString);
184+ if ( inputFieldArgumentsString ) {
185+ inputFieldDeclaration . argumentContainer = InputFieldDeclarationParser . parseArguments ( inputFieldArgumentsString , inputFieldDeclaration . inputFieldType ) ;
186+ } else {
187+ inputFieldDeclaration . argumentContainer = new InputFieldArgumentContainer ( ) ;
188+ }
176189 } else {
190+ inputFieldDeclaration . inputFieldType = InputFieldType . INVALID ;
177191 inputFieldDeclaration . argumentContainer = new InputFieldArgumentContainer ( ) ;
178192 }
179- } else {
180- inputFieldDeclaration . inputFieldType = InputFieldType . INVALID ;
181- inputFieldDeclaration . argumentContainer = new InputFieldArgumentContainer ( ) ;
182- }
183193
184- if ( useTemplate ) {
185- InputFieldDeclarationParser . applyTemplate ( inputFieldDeclaration , templateName ) ;
186- }
194+ if ( useTemplate ) {
195+ InputFieldDeclarationParser . applyTemplate ( inputFieldDeclaration , templateName ) ;
196+ }
187197
188- if ( inputFieldDeclaration . inputFieldType === InputFieldType . INVALID ) {
189- throw new MetaBindParsingError ( `unknown input field type` ) ;
198+ if ( inputFieldDeclaration . inputFieldType === InputFieldType . INVALID ) {
199+ throw new MetaBindParsingError ( `unknown input field type` ) ;
200+ }
201+ } catch ( e ) {
202+ if ( e instanceof Error ) {
203+ inputFieldDeclaration . error = e ;
204+ console . warn ( e ) ;
205+ }
190206 }
191207
192208 return inputFieldDeclaration ;
0 commit comments