Skip to content

Commit

Permalink
enchancement: report which property is triggering a parsing error (#1439
Browse files Browse the repository at this point in the history
)
  • Loading branch information
sakishrist authored Jul 20, 2023
1 parent d0f9dc5 commit 27b27bd
Showing 1 changed file with 8 additions and 8 deletions.
16 changes: 8 additions & 8 deletions parser.go
Original file line number Diff line number Diff line change
Expand Up @@ -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)
}
}

Expand Down Expand Up @@ -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
}

Expand Down Expand Up @@ -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 {
Expand All @@ -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 {
Expand All @@ -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 {
Expand Down

0 comments on commit 27b27bd

Please sign in to comment.