Skip to content

Commit 9707c3d

Browse files
committed
refactor: log and error reporting on startup
- reduce log verbosity - downgrade some errors to warnings regarding missing profile paths
1 parent e4cd1fe commit 9707c3d

File tree

13 files changed

+55
-40
lines changed

13 files changed

+55
-40
lines changed

CHANGELOG.md

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,11 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
77

88
## [Unreleased]
99

10+
### Fixed
11+
12+
- Log browser profile path errors as warnings
13+
- Reduce log verbosity on default level
14+
1015
## [1.1.0] 2025-07-29
1116

1217
### Added

browsers/chrome/chrome.go

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,6 @@
3030
package chrome
3131

3232
import (
33-
"errors"
3433
"fmt"
3534
"os"
3635
"path/filepath"
@@ -207,10 +206,11 @@ func (ch *Chrome) setupWatchers() error {
207206

208207
ok, err := modules.SetupWatchers(ch.BrowserConfig, w)
209208
if err != nil {
210-
return fmt.Errorf("could not setup watcher: %w", err)
209+
log.Error(err)
210+
return modules.ErrWatcherSetup
211211
}
212212
if !ok {
213-
return errors.New("could not setup watcher")
213+
return modules.ErrWatcherSetup
214214
}
215215

216216
return nil

browsers/firefox/firefox.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,6 @@
2222
package firefox
2323

2424
import (
25-
"errors"
2625
"fmt"
2726
"path"
2827
"path/filepath"
@@ -372,7 +371,7 @@ func (f *Firefox) Init(ctx *modules.Context, p *profiles.Profile) error {
372371
// TEST:
373372
// Implements browser.Initializer interface
374373
func (f *Firefox) init(ctx *modules.Context) error {
375-
log.Infof("initializing <%s>", f.fullID())
374+
log.Debugf("initializing <%s>", f.fullID())
376375

377376
watchedPath := f.BkDir
378377
log.Debugf("Watching path: %s", watchedPath)
@@ -387,11 +386,12 @@ func (f *Firefox) init(ctx *modules.Context) error {
387386

388387
ok, err := modules.SetupWatchersWithReducer(f.BrowserConfig, modules.ReducerChanLen, w)
389388
if err != nil {
390-
return fmt.Errorf("could not setup watcher: %w", err)
389+
log.Error(err)
390+
return modules.ErrWatcherSetup
391391
}
392392

393393
if !ok {
394-
return errors.New("could not setup watcher")
394+
return modules.ErrWatcherSetup
395395
}
396396

397397
/*

cmd/gosuki/daemon.go

Lines changed: 10 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -90,8 +90,8 @@ func runBrowserModule(m *manager.Manager,
9090
return err
9191
}
9292
if err := bpm.UseProfile(pfl, flav); err != nil {
93-
log.Errorf("could not use profile <%s>", pfl.Name)
94-
return err
93+
log.Warnf("unable to load profile <%s.%s>: %s", mod.ID, pfl.Name, err)
94+
return &modules.ErrModDisabled{Err: err}
9595
}
9696
profileName = pfl.Name
9797
}
@@ -108,8 +108,7 @@ func runBrowserModule(m *manager.Manager,
108108
// calls the setup logic for each browser instance which
109109
// includes the browsers.Initializer and browsers.Loader interfaces
110110
//PERF:
111-
err := modules.SetupBrowser(browser, modContext, pfl)
112-
if err != nil {
111+
if err := modules.SetupBrowser(browser, modContext, pfl); err != nil {
113112
return err
114113
}
115114

@@ -207,7 +206,7 @@ func startNormalDaemon(ctx context.Context, cmd *cli.Command, mngr *manager.Mana
207206

208207
// Setup the module
209208
if err := modules.SetupModule(mod, modContext); err != nil {
210-
log.Error(err, "mod", name)
209+
log.Warn(err, "mod", name)
211210
continue
212211
}
213212

@@ -251,8 +250,8 @@ func startNormalDaemon(ctx context.Context, cmd *cli.Command, mngr *manager.Mana
251250
log.Debug("", "flavour", flav.Flavour, "profile", p.Name)
252251
err = runBrowserModule(mngr, ctx, cmd, browserMod, p, &flav)
253252
if err != nil {
254-
if _, errDisable := err.(*modules.ModDisabledError); errDisable {
255-
log.Info("disabling module", "mod", browserMod.ModInfo().ID)
253+
if errDisabled, errDisable := err.(*modules.ErrModDisabled); errDisable {
254+
log.Warn("disabling browser profile", "profile", p.Name, "mod", browserMod.ModInfo().ID, "reason", errDisabled.Reason)
256255
modules.Disable(browserMod.ModInfo().ID)
257256
} else {
258257
log.Error(err, "browser", flav.Flavour)
@@ -266,8 +265,8 @@ func startNormalDaemon(ctx context.Context, cmd *cli.Command, mngr *manager.Mana
266265
browser.Config().Name)
267266
err := runBrowserModule(mngr, ctx, cmd, browserMod, nil, nil)
268267
if err != nil {
269-
if _, errDisable := err.(*modules.ModDisabledError); errDisable {
270-
log.Info("disabling module", "mod", browserMod.ModInfo().ID)
268+
if _, errDisable := err.(*modules.ErrModDisabled); errDisable {
269+
log.Warn("disabling browser", "mod", browserMod.ModInfo().ID)
271270
modules.Disable(browserMod.ModInfo().ID)
272271
} else {
273272
log.Error(err, "browser", browserMod.Config().Name)
@@ -279,8 +278,8 @@ func startNormalDaemon(ctx context.Context, cmd *cli.Command, mngr *manager.Mana
279278
log.Info("not implemented profiles.ProfileManager", "browser",
280279
browser.Config().Name)
281280
if err := runBrowserModule(mngr, ctx, cmd, browserMod, nil, nil); err != nil {
282-
if _, errDisable := err.(*modules.ModDisabledError); errDisable {
283-
log.Info("disabling module", "mod", browserMod.ModInfo().ID)
281+
if _, errDisable := err.(*modules.ErrModDisabled); errDisable {
282+
log.Warn("disabling browser", "mod", browserMod.ModInfo().ID)
284283
modules.Disable(browserMod.ModInfo().ID)
285284
} else {
286285
log.Error(err, "browser", browser.Config().Name)

internal/database/init.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -58,7 +58,7 @@ func Init() {
5858
// If local db exists load it to cacheDB
5959
if exists, err := utils.CheckFileExists(dbpath); exists {
6060

61-
log.Infof("<%s> exists, preloading to cache", dbpath)
61+
log.Infof("preloading <%s> to cache", dbpath)
6262
err = InitDiskConn(dbpath)
6363
if err != nil {
6464
log.Fatal(err)

internal/database/load.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ func LoadBookmarks(load loadFunc, modName string) error {
4646
}
4747

4848
if len(marks) == 0 {
49-
log.Warn("no bookmarks fetched", "module", modName)
49+
log.Info("no bookmarks loaded", "module", modName)
5050
return nil
5151
}
5252

mods/github/mod.go

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@ package stars
99

1010
import (
1111
"context"
12-
"errors"
1312
"fmt"
1413
"os"
1514
"sync"
@@ -78,7 +77,7 @@ func (sf *StarFetcher) Init(ctx *modules.Context) error {
7877
// Check if the environment variable GH_API_TOKEN is set
7978
if len(Config.GithubToken) == 0 {
8079
if sfModel.token = os.Getenv("GS_GITHUB_TOKEN"); sfModel.token == "" {
81-
return errors.New("no github token in config and GS_GITHUB_TOKEN environment variable not set")
80+
return &modules.ErrModDisabled{Err: modules.ErrMissingCredentials}
8281
}
8382
} else {
8483
sfModel.token = Config.GithubToken

pkg/manager/manager.go

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -127,10 +127,10 @@ func (m *Manager) Start() {
127127

128128
log.Info("manager is up")
129129
if !logging.TUIMode {
130-
fmt.Println("gosuki service up and running")
130+
fmt.Println("Gosuki service up and running")
131131
for name := range m.Units() {
132132
if strings.HasPrefix(name, "webui") {
133-
fmt.Printf("WebUI listening on: http://%s\n", webui.BindAddr)
133+
fmt.Printf("GUI listening on: http://%s\n", webui.BindAddr)
134134
}
135135
}
136136
}

pkg/marktab/parse.go

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -152,7 +152,7 @@ func PreloadRules() error {
152152
func (mt *MarkTab) LoadMarktabs() error {
153153
path, err := utils.ExpandPath(marktabPath)
154154
if os.IsNotExist(err) {
155-
log.Warnf("skipping marktab, not found: %v", marktabPath)
155+
log.Infof("skipping marktab, not found: %v", marktabPath)
156156
return nil
157157

158158
} else if err != nil {

pkg/modules/browser.go

Lines changed: 9 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ func (b BrowserConfig) RebuildIndex() {
210210
func SetupBrowser(browser BrowserModule, c *Context, p *profiles.Profile) error {
211211

212212
browserID := browser.ModInfo().ID
213-
log.Info("setting up", "browser", browserID)
213+
log.Debug("setting up", "browser", browserID)
214214

215215
// Handle Initializers custom Init from Browser module
216216
initializer, okInit := browser.(Initializer)
@@ -228,9 +228,11 @@ func SetupBrowser(browser BrowserModule, c *Context, p *profiles.Profile) error
228228
log.Debugf("<%s> custom init", browserID)
229229
if err := initializer.Init(c); err != nil {
230230
if _, pathErr := err.(*fs.PathError); pathErr {
231-
return &ModDisabledError{MissingPath, err}
231+
return &ErrModDisabled{MissingPath, err}
232+
} else if err == ErrWatcherSetup {
233+
return &ErrModDisabled{MissingPath, err}
232234
}
233-
return fmt.Errorf("initialization error: %w", err)
235+
return fmt.Errorf("init: %w", err)
234236
}
235237
}
236238

@@ -241,7 +243,10 @@ func SetupBrowser(browser BrowserModule, c *Context, p *profiles.Profile) error
241243
}
242244

243245
if err := pInitializer.Init(c, p); err != nil {
244-
return fmt.Errorf("initialization error: %w", err)
246+
if err == ErrWatcherSetup {
247+
return &ErrModDisabled{MissingPath, err}
248+
}
249+
return fmt.Errorf("init: %w", err)
245250
}
246251
}
247252

0 commit comments

Comments
 (0)