Skip to content

Commit

Permalink
Merge pull request jorgerojas26#133 from svanharmelen/feat/errors
Browse files Browse the repository at this point in the history
Do not try to recover from panics, but use the return values
  • Loading branch information
jorgerojas26 authored and Mariusz Kuchta committed Nov 25, 2024
2 parents 0bc5564 + cbb5477 commit b6da88a
Show file tree
Hide file tree
Showing 2 changed files with 43 additions and 56 deletions.
17 changes: 3 additions & 14 deletions components/ResultsTable.go
Original file line number Diff line number Diff line change
Expand Up @@ -812,32 +812,21 @@ func (table *ResultsTable) SetResultsInfo(text string) {
}

func (table *ResultsTable) SetLoading(show bool) {
defer func() {
if r := recover(); r != nil {
logger.Error("ResultsTable.go:800 => Recovered from panic", map[string]any{"error": r})
_ = table.Page.HidePage(pageNameTableLoading)
if table.state.error != "" {
App.SetFocus(table.Error)
} else {
App.SetFocus(table)
}
}
}()

table.state.isLoading = show

if show {
table.Page.ShowPage(pageNameTableLoading)
App.SetFocus(table.Loading)
App.ForceDraw()
} else {
table.Page.HidePage(pageNameTableLoading)
if table.state.error != "" {
App.SetFocus(table.Error)
} else {
App.SetFocus(table)
}
App.ForceDraw()
}

App.ForceDraw()
}

func (table *ResultsTable) SetIsEditing(editing bool) {
Expand Down
82 changes: 40 additions & 42 deletions drivers/postgres.go
Original file line number Diff line number Diff line change
Expand Up @@ -98,13 +98,13 @@ func (db *Postgres) GetTables(database string) (tables map[string][]string, err
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

query := "SELECT table_name, table_schema FROM information_schema.tables WHERE table_catalog = $1"
rows, err := db.Connection.Query(query, database)
Expand Down Expand Up @@ -151,13 +151,13 @@ func (db *Postgres) GetTableColumns(database, table string) (results [][]string,
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

tableSchema := splitTableString[0]
tableName := splitTableString[1]
Expand Down Expand Up @@ -223,13 +223,13 @@ func (db *Postgres) GetConstraints(database, table string) (constraints [][]stri
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

tableSchema := splitTableString[0]
tableName := splitTableString[1]
Expand Down Expand Up @@ -306,13 +306,13 @@ func (db *Postgres) GetForeignKeys(database, table string) (foreignKeys [][]stri
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

tableSchema := splitTableString[0]
tableName := splitTableString[1]
Expand Down Expand Up @@ -390,13 +390,13 @@ func (db *Postgres) GetIndexes(database, table string) (indexes [][]string, err
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

tableSchema := splitTableString[0]
tableName := splitTableString[1]
Expand Down Expand Up @@ -483,15 +483,13 @@ func (db *Postgres) GetRecords(database, table, where, sort string, offset, limi
if err != nil {
return nil, 0, err
}
}

defer func() {
if r := recover(); r != nil {
if database != db.PreviousDatabase {
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}
}()
}()
}

tableSchema := splitTableString[0]
tableName := splitTableString[1]
Expand Down Expand Up @@ -872,13 +870,13 @@ func (db *Postgres) GetPrimaryKeyColumnNames(database, table string) (primaryKey
if err != nil {
return nil, err
}
}

defer func() {
if r := recover(); r != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
defer func() {
if err != nil {
_ = db.SwitchDatabase(db.PreviousDatabase)
}
}()
}

tableName := splitTableString[1]

Expand Down

0 comments on commit b6da88a

Please sign in to comment.