diff --git a/compiler/src/model/build-model.ts b/compiler/src/model/build-model.ts index 303499c87a..b450125768 100644 --- a/compiler/src/model/build-model.ts +++ b/compiler/src/model/build-model.ts @@ -479,15 +479,25 @@ function compileClassOrInterfaceDeclaration (declaration: ClassDeclaration | Int Node.isPropertyDeclaration(member) || Node.isPropertySignature(member), 'Class and interfaces can only have property declarations or signatures' ) - const property = modelProperty(member) - if (type.variants?.kind === 'container' && property.containerProperty == null) { - assert( - member, - !property.required, - 'All @variants container properties must be optional' - ) + try { + const property = modelProperty(member) + if (type.variants?.kind === 'container' && property.containerProperty == null) { + assert( + member, + !property.required, + 'All @variants container properties must be optional' + ) + } + type.properties.push(property) + } catch (e) { + const name = declaration.getName() + if (name !== undefined) { + console.log(`failed to parse ${name}, reason:`, e.message) + } else { + console.log('failed to parse field, reason:', e.message) + } + process.exit(1) } - type.properties.push(property) } // The class or interface is extended, an extended class or interface could diff --git a/compiler/src/model/utils.ts b/compiler/src/model/utils.ts index 01c60023ca..9f6d953957 100644 --- a/compiler/src/model/utils.ts +++ b/compiler/src/model/utils.ts @@ -532,10 +532,15 @@ export function modelProperty (declaration: PropertySignature | PropertyDeclarat // names that contains `.` or `-` will be wrapped inside single quotes const name = declaration.getName().replace(/'/g, '') - const property = { - name, - required: !declaration.hasQuestionToken(), - type: modelType(type) + let property: model.Property + try { + property = { + name, + required: !declaration.hasQuestionToken(), + type: modelType(type) + } + } catch (e) { + throw new Error(`cannot determine type of ${name}, got:${type.getFullText()}`) } hoistPropertyAnnotations(property, declaration.getJsDocs()) return property