mirror of
https://github.com/garraflavatra/rolens.git
synced 2025-07-22 15:18:02 +00:00
Improved error logging and dialogs
This commit is contained in:
@ -1,7 +1,6 @@
|
||||
package app
|
||||
|
||||
import (
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
)
|
||||
@ -22,24 +21,32 @@ func (a *App) OpenDatabase(hostKey, dbKey string) (result OpenDatabaseResult) {
|
||||
command := bson.M{"dbStats": 1}
|
||||
err = client.Database(dbKey).RunCommand(ctx, command).Decode(&result.Stats)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve database stats for "+dbKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
runtime.LogWarningf(a.ctx, "Could not retrieve database stats for %s: %s", dbKey, err.Error())
|
||||
result.StatsError = err.Error()
|
||||
}
|
||||
|
||||
result.Collections, err = client.Database(dbKey).ListCollectionNames(ctx, bson.D{})
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not retrieve collection list for db "+dbKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Error while getting collections"), zenity.ErrorIcon)
|
||||
runtime.LogWarningf(a.ctx, "Could not retrieve collection list for db %s: %s", dbKey, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Error getting collection list",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
}
|
||||
|
||||
return
|
||||
}
|
||||
|
||||
func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
||||
err := zenity.Question("Are you sure you want to drop "+dbKey+"?", zenity.Title("Confirm"), zenity.WarningIcon)
|
||||
if err == zenity.ErrCanceled {
|
||||
choice, _ := runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Confirm",
|
||||
Message: "Are you sure you want to drop " + dbKey + "?",
|
||||
Buttons: []string{"Yes", "Cancel"},
|
||||
DefaultButton: "Yes",
|
||||
CancelButton: "Cancel",
|
||||
})
|
||||
if choice != "Yes" {
|
||||
return false
|
||||
}
|
||||
|
||||
@ -51,9 +58,12 @@ func (a *App) DropDatabase(hostKey, dbKey string) bool {
|
||||
|
||||
err = client.Database(dbKey).Drop(ctx)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not drop db "+dbKey)
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Error while dropping database"), zenity.ErrorIcon)
|
||||
runtime.LogWarningf(a.ctx, "Could not drop db %s: %s", dbKey, err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Error dropping database",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
return false
|
||||
}
|
||||
|
||||
|
Reference in New Issue
Block a user