Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Do not try to recover from panics, but use the return values #133

Merged
merged 1 commit into from
Nov 22, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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