From 27b27bd7e0c59917a15aa9a6508cc85ba731347c Mon Sep 17 00:00:00 2001 From: Sakis Date: Thu, 20 Jul 2023 04:29:30 +0300 Subject: [PATCH] enchancement: report which property is triggering a parsing error (#1439) --- parser.go | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/parser.go b/parser.go index 817510700..6bf991e92 100644 --- a/parser.go +++ b/parser.go @@ -1139,7 +1139,7 @@ func (parser *Parser) getTypeSchema(typeName string, file *ast.File, ref bool) ( if err == ErrRecursiveParseStruct && ref { return parser.getRefTypeSchema(typeSpecDef, schema), nil } - return nil, err + return nil, fmt.Errorf("%s: %w", typeName, err) } } @@ -1373,7 +1373,7 @@ func (parser *Parser) parseStruct(file *ast.File, fields *ast.FieldList) (*spec. for _, field := range fields.List { fieldProps, requiredFromAnon, err := parser.parseStructField(file, field) if err != nil { - if err == ErrFuncTypeField || err == ErrSkippedField { + if errors.Is(err, ErrFuncTypeField) || errors.Is(err, ErrSkippedField) { continue } @@ -1424,12 +1424,12 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st if fieldName == "" { typeName, err := getFieldType(file, field.Type, nil) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } schema, err := parser.getTypeSchema(typeName, file, false) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } if len(schema.Type) > 0 && schema.Type[0] == OBJECT { @@ -1451,7 +1451,7 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st schema, err := ps.CustomSchema() if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } if schema == nil { @@ -1465,20 +1465,20 @@ func (parser *Parser) parseStructField(file *ast.File, field *ast.Field) (map[st } if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } } err = ps.ComplementSchema(schema) if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } var tagRequired []string required, err := ps.IsRequired() if err != nil { - return nil, nil, err + return nil, nil, fmt.Errorf("%s: %w", fieldName, err) } if required {