@@ -254,17 +254,22 @@ export function interpretZodValue(
254254 }
255255 return { message : `Invalid number type: ${ entry } ` , success : false } ;
256256 case 'ZodSet' :
257- if ( entry . startsWith ( 'SET(' ) ) {
258- const setData = extractSetEntry ( entry ) ;
259- const values = setData
260- . split ( ',' )
261- . map ( ( s ) => s . trim ( ) )
262- . filter ( Boolean ) ;
263- if ( values . length === 0 ) {
264- return { message : 'Empty set is not allowed' , success : false } ;
257+ try {
258+ if ( entry . startsWith ( 'SET(' ) ) {
259+ const setData = extractSetEntry ( entry ) ;
260+ const values = setData
261+ . split ( ',' )
262+ . map ( ( s ) => s . trim ( ) )
263+ . filter ( Boolean ) ;
264+ if ( values . length === 0 ) {
265+ return { message : 'Empty set is not allowed' , success : false } ;
266+ }
267+ return { success : true , value : new Set ( values ) } ;
265268 }
266- return { success : true , value : new Set ( values ) } ;
269+ } catch {
270+ return { message : 'Error occurred interpreting set entry' , success : false } ;
267271 }
272+
268273 return { message : `Invalid ZodSet: ${ entry } ` , success : false } ;
269274 case 'ZodString' :
270275 return { success : true , value : entry } ;
@@ -279,63 +284,70 @@ export function interpretZodObjectValue(
279284 zList : ZodTypeNameResult [ ] ,
280285 zKeys : string [ ]
281286) : UploadOperationResult < FormTypes . FieldValue > {
282- if ( entry === '' && isOptional ) {
283- return { success : true , value : undefined } ;
284- } else if ( ! entry . startsWith ( 'RECORD_ARRAY(' ) ) {
285- return { message : `Invalid ZodType` , success : false } ;
286- }
287+ try {
288+ if ( entry === '' && isOptional ) {
289+ return { success : true , value : undefined } ;
290+ } else if ( ! entry . startsWith ( 'RECORD_ARRAY(' ) ) {
291+ return { message : `Invalid ZodType` , success : false } ;
292+ }
287293
288- const recordArray : { [ key : string ] : any } [ ] = [ ] ;
289- const recordArrayDataEntry = extractRecordArrayEntry ( entry ) ;
290- const recordArrayDataList = recordArrayDataEntry . split ( ';' ) ;
294+ const recordArray : { [ key : string ] : any } [ ] = [ ] ;
295+ const recordArrayDataEntry = extractRecordArrayEntry ( entry ) ;
296+ const recordArrayDataList = recordArrayDataEntry . split ( ';' ) ;
291297
292- if ( recordArrayDataList . at ( - 1 ) === '' ) {
293- recordArrayDataList . pop ( ) ;
294- }
298+ if ( recordArrayDataList . at ( - 1 ) === '' ) {
299+ recordArrayDataList . pop ( ) ;
300+ }
295301
296- for ( const listData of recordArrayDataList ) {
297- const recordArrayObject : { [ key : string ] : any } = { } ;
302+ for ( const listData of recordArrayDataList ) {
303+ const recordArrayObject : { [ key : string ] : any } = { } ;
298304
299- const record = listData . split ( ',' ) ;
305+ const record = listData . split ( ',' ) ;
300306
301- if ( ! record ) {
302- return { message : `Record in the record array was left undefined` , success : false } ;
303- }
304- if ( record . some ( ( str ) => str === '' ) ) {
305- return { message : `One or more of the record array fields was left empty` , success : false } ;
306- }
307- if ( ! ( zList . length === zKeys . length && zList . length === record . length ) ) {
308- return { message : `Incorrect number of entries for record array` , success : false } ;
309- }
310- for ( let i = 0 ; i < record . length ; i ++ ) {
311- if ( ! record [ i ] ) {
312- return { message : `Failed to interpret field '${ i } '` , success : false } ;
307+ if ( ! record ) {
308+ return { message : `Record in the record array was left undefined` , success : false } ;
313309 }
314-
315- const recordValue = record [ i ] ! . split ( ':' ) [ 1 ] ! . trim ( ) ;
316-
317- const zListResult = zList [ i ] ! ;
318- if ( ! ( zListResult . success && zListResult . typeName !== 'ZodArray' && zListResult . typeName !== 'ZodObject' ) ) {
319- return { message : `Failed to interpret field '${ i } '` , success : false } ;
310+ if ( record . some ( ( str ) => str === '' ) ) {
311+ return { message : `One or more of the record array fields was left empty` , success : false } ;
320312 }
321- const interpretZodValueResult : UploadOperationResult < FormTypes . FieldValue > = interpretZodValue (
322- recordValue ,
323- zListResult . typeName ,
324- zListResult . isOptional
325- ) ;
326- if ( ! interpretZodValueResult . success ) {
327- return {
328- message : `failed to interpret value at entry ${ i } in record array row ${ listData } ` ,
329- success : false
330- } ;
313+ if ( ! ( zList . length === zKeys . length && zList . length === record . length ) ) {
314+ return { message : `Incorrect number of entries for record array` , success : false } ;
331315 }
316+ for ( let i = 0 ; i < record . length ; i ++ ) {
317+ if ( ! record [ i ] ) {
318+ return { message : `Failed to interpret field '${ i } '` , success : false } ;
319+ }
320+
321+ const recordValue = record [ i ] ! . split ( ':' ) [ 1 ] ! . trim ( ) ;
322+
323+ const zListResult = zList [ i ] ! ;
324+ if ( ! ( zListResult . success && zListResult . typeName !== 'ZodArray' && zListResult . typeName !== 'ZodObject' ) ) {
325+ return { message : `Failed to interpret field '${ i } '` , success : false } ;
326+ }
327+ const interpretZodValueResult : UploadOperationResult < FormTypes . FieldValue > = interpretZodValue (
328+ recordValue ,
329+ zListResult . typeName ,
330+ zListResult . isOptional
331+ ) ;
332+ if ( ! interpretZodValueResult . success ) {
333+ return {
334+ message : `failed to interpret value at entry ${ i } in record array row ${ listData } ` ,
335+ success : false
336+ } ;
337+ }
332338
333- recordArrayObject [ zKeys [ i ] ! ] = interpretZodValueResult . value ;
339+ recordArrayObject [ zKeys [ i ] ! ] = interpretZodValueResult . value ;
340+ }
341+ recordArray . push ( recordArrayObject ) ;
334342 }
335- recordArray . push ( recordArrayObject ) ;
336- }
337343
338- return { success : true , value : recordArray } ;
344+ return { success : true , value : recordArray } ;
345+ } catch {
346+ return {
347+ message : `failed to interpret record array entries` ,
348+ success : false
349+ } ;
350+ }
339351}
340352
341353function formatTypeInfo ( s : string , isOptional : boolean ) {
0 commit comments