From 5fb2ffe5d6f58844f052729a09b1e75fd26cd04b Mon Sep 17 00:00:00 2001 From: Sander van Harmelen Date: Fri, 22 Nov 2024 11:54:15 +0100 Subject: [PATCH] Do not try to recover from panics, but use the return values --- components/ResultsTable.go | 17 ++------ drivers/postgres.go | 82 +++++++++++++++++++------------------- 2 files changed, 43 insertions(+), 56 deletions(-) diff --git a/components/ResultsTable.go b/components/ResultsTable.go index 4b3866e..551fef7 100644 --- a/components/ResultsTable.go +++ b/components/ResultsTable.go @@ -812,23 +812,11 @@ 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 != "" { @@ -836,8 +824,9 @@ func (table *ResultsTable) SetLoading(show bool) { } else { App.SetFocus(table) } - App.ForceDraw() } + + App.ForceDraw() } func (table *ResultsTable) SetIsEditing(editing bool) { diff --git a/drivers/postgres.go b/drivers/postgres.go index 1097bcb..546221f 100644 --- a/drivers/postgres.go +++ b/drivers/postgres.go @@ -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) @@ -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] @@ -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] @@ -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] @@ -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] @@ -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] @@ -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]