Skip to content

Commit

Permalink
Fix null reference panic
Browse files Browse the repository at this point in the history
  • Loading branch information
Svetlin Ralchev committed Oct 7, 2019
1 parent af35b33 commit f88c8c5
Show file tree
Hide file tree
Showing 4 changed files with 17 additions and 11 deletions.
6 changes: 4 additions & 2 deletions cmd/migration.go
Original file line number Diff line number Diff line change
Expand Up @@ -128,8 +128,10 @@ func (m *SQLMigration) before(ctx *cli.Context) error {
}

func (m *SQLMigration) after(ctx *cli.Context) error {
if err := m.db.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeMigration)
if m.db != nil {
if err := m.db.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeMigration)
}
}

return nil
Expand Down
6 changes: 4 additions & 2 deletions cmd/model.go
Original file line number Diff line number Diff line change
Expand Up @@ -156,8 +156,10 @@ func (m *SQLModel) builder(ctx *cli.Context) (sqlmodel.TagBuilder, error) {
}

func (m *SQLModel) after(ctx *cli.Context) error {
if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
if m.executor != nil {
if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
}
}
return nil
}
Expand Down
7 changes: 5 additions & 2 deletions cmd/repository.go
Original file line number Diff line number Diff line change
Expand Up @@ -125,9 +125,12 @@ func (m *SQLRepository) before(ctx *cli.Context) error {
}

func (m *SQLRepository) after(ctx *cli.Context) error {
if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
if m.executor != nil {
if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
}
}

return nil
}

Expand Down
9 changes: 4 additions & 5 deletions cmd/routine.go
Original file line number Diff line number Diff line change
Expand Up @@ -202,13 +202,12 @@ func (m *SQLRoutine) run(ctx *cli.Context) error {
}

func (m *SQLRoutine) after(ctx *cli.Context) error {
if m.executor == nil {
return nil
if m.executor != nil {
if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
}
}

if err := m.executor.Provider.Close(); err != nil {
return cli.NewExitError(err.Error(), ErrCodeSchema)
}
return nil
}

Expand Down

0 comments on commit f88c8c5

Please sign in to comment.