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:
@ -2,9 +2,7 @@ package app
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
|
||||
"github.com/ncruces/zenity"
|
||||
"github.com/wailsapp/wails/v2/pkg/runtime"
|
||||
"go.mongodb.org/mongo-driver/bson"
|
||||
"go.mongodb.org/mongo-driver/mongo"
|
||||
@ -14,17 +12,23 @@ import (
|
||||
func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson string) {
|
||||
var settings *options.AggregateOptions
|
||||
if err := json.Unmarshal([]byte(settingsJson), &settings); err != nil {
|
||||
runtime.LogError(a.ctx, "Could not parse aggregation settings:")
|
||||
runtime.LogError(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Couldn't parse aggregation settings"), zenity.ErrorIcon)
|
||||
runtime.LogErrorf(a.ctx, "Could not parse aggregation settings: %s", err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Couldn't parse aggregation settings",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var pipeline mongo.Pipeline
|
||||
if err := bson.UnmarshalExtJSON([]byte(pipelineJson), true, &pipeline); err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not parse aggregation pipeline:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Couldn't parse aggregation pipeline"), zenity.ErrorIcon)
|
||||
runtime.LogWarningf(a.ctx, "Could not parse aggregation pipeline: %s", err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Couldn't parse aggregation pipeline",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
@ -37,19 +41,23 @@ func (a *App) Aggregate(hostKey, dbKey, collKey, pipelineJson, settingsJson stri
|
||||
|
||||
cursor, err := client.Database(dbKey).Collection(collKey).Aggregate(ctx, pipeline, settings)
|
||||
if err != nil {
|
||||
runtime.LogWarning(a.ctx, "Could not get aggregation cursor:")
|
||||
runtime.LogWarning(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Couldn't get aggregation cursor"), zenity.ErrorIcon)
|
||||
runtime.LogWarningf(a.ctx, "Could not get aggregation cursor: %s", err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Couldn't get aggregation cursor",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
var results []bson.M
|
||||
if err := cursor.All(ctx, &results); err != nil {
|
||||
runtime.LogInfo(a.ctx, "Error while running aggregation pipeline:")
|
||||
runtime.LogInfo(a.ctx, err.Error())
|
||||
zenity.Error(err.Error(), zenity.Title("Error while running aggregation pipeline"), zenity.ErrorIcon)
|
||||
runtime.LogInfof(a.ctx, "Error while running aggregation pipeline: %s", err.Error())
|
||||
runtime.MessageDialog(a.ctx, runtime.MessageDialogOptions{
|
||||
Title: "Error while running aggregation pipeline",
|
||||
Message: err.Error(),
|
||||
Type: runtime.ErrorDialog,
|
||||
})
|
||||
return
|
||||
}
|
||||
|
||||
fmt.Println(results)
|
||||
}
|
||||
|
Reference in New Issue
Block a user