Skip to content

Commit a53b27f

Browse files
alecbzkyleconroy
andauthored
Return an error from Schema.Add when the table spec is nil (#608)
Ran into this error when trying to process a SQL file introducing a view, and it was hard to chase down. Co-authored-by: Kyle Conroy <kyle@conroy.org>
1 parent 939d879 commit a53b27f

2 files changed

Lines changed: 4 additions & 4 deletions

File tree

internal/mysql/parse.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -123,8 +123,7 @@ func (pGen PackageGenerator) parseQueryString(tree sqlparser.Statement, query st
123123
}
124124
parsedQuery = delete
125125
case *sqlparser.DDL:
126-
pGen.Schema.Add(tree)
127-
return nil, nil
126+
return nil, pGen.Schema.Add(tree)
128127
default:
129128
// panic("Unsupported SQL statement type")
130129
return nil, nil

internal/mysql/schema.go

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -55,15 +55,16 @@ func tableColReferences(col *sqlparser.ColName, defaultTable string, tableAliasM
5555
}
5656

5757
// Add add a MySQL table definition to the schema map
58-
func (s *Schema) Add(ddl *sqlparser.DDL) {
58+
func (s *Schema) Add(ddl *sqlparser.DDL) error {
5959
switch ddl.Action {
6060
case "create":
6161
name := ddl.Table.Name.String()
6262
if ddl.TableSpec == nil {
63-
panic(fmt.Sprintf("failed to parse table \"%s\" schema.", name))
63+
return fmt.Errorf("failed to parse table \"%s\" schema", name)
6464
}
6565
s.tables[name] = ddl.TableSpec.Columns
6666
}
67+
return nil
6768
}
6869

6970
func (s *Schema) schemaLookup(table string, col string) (*Column, error) {

0 commit comments

Comments
 (0)