mirror of
https://github.com/moonD4rk/HackBrowserData.git
synced 2026-05-19 18:58:03 +02:00
style: add more debug log
This commit is contained in:
@@ -46,12 +46,11 @@ func pickChromium(name, profile string) []Browser {
|
||||
log.Noticef("find browser %s success", b.Name())
|
||||
browsers = append(browsers, b)
|
||||
} else {
|
||||
// TODO: show which browser find failed
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == chromium.ErrProfilePathNotFound {
|
||||
log.Errorf("find browser %s failed, profile folder is not exist, maybe not installed", v.name)
|
||||
continue
|
||||
} else {
|
||||
log.Errorf("new chromium error:", err)
|
||||
log.Errorf("new chromium error: %s", err.Error())
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -62,10 +61,11 @@ func pickChromium(name, profile string) []Browser {
|
||||
}
|
||||
b, err := chromium.New(c.name, c.storage, profile, c.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == chromium.ErrProfilePathNotFound {
|
||||
log.Fatalf("find browser %s failed, profile folder is not exist, maybe not installed", c.name)
|
||||
} else {
|
||||
log.Fatalf("new chromium error:", err)
|
||||
return nil
|
||||
}
|
||||
}
|
||||
browsers = append(browsers, b)
|
||||
@@ -89,13 +89,12 @@ func pickFirefox(name, profile string) []Browser {
|
||||
browsers = append(browsers, b)
|
||||
}
|
||||
} else {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
if err == firefox.ErrProfilePathNotFound {
|
||||
log.Errorf("find browser firefox %s failed, profile folder is not exist", v.name)
|
||||
} else {
|
||||
log.Error(err)
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
return browsers
|
||||
}
|
||||
@@ -128,9 +127,5 @@ const (
|
||||
coccocName = "CocCoc"
|
||||
yandexName = "Yandex"
|
||||
|
||||
firefoxName = "Firefox"
|
||||
firefoxBetaName = "Firefox Beta"
|
||||
firefoxDevName = "Firefox Dev"
|
||||
firefoxNightlyName = "Firefox Nightly"
|
||||
firefoxESRName = "Firefox ESR"
|
||||
firefoxName = "Firefox"
|
||||
)
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
package chromium
|
||||
|
||||
import (
|
||||
"fmt"
|
||||
"errors"
|
||||
"io/ioutil"
|
||||
"os"
|
||||
"path/filepath"
|
||||
@@ -22,6 +22,10 @@ type chromium struct {
|
||||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
)
|
||||
|
||||
// New create instance of chromium browser, fill item's path if item is existed.
|
||||
func New(name, storage, profilePath string, items []item.Item) (*chromium, error) {
|
||||
c := &chromium{
|
||||
@@ -30,7 +34,7 @@ func New(name, storage, profilePath string, items []item.Item) (*chromium, error
|
||||
}
|
||||
// TODO: Handle file path is not exist
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
|
||||
return nil, ErrProfilePathNotFound
|
||||
}
|
||||
itemsPaths, err := c.getItemPath(profilePath, items)
|
||||
if err != nil {
|
||||
|
||||
@@ -1,15 +1,14 @@
|
||||
package firefox
|
||||
|
||||
import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"io/fs"
|
||||
"io/ioutil"
|
||||
"path/filepath"
|
||||
"strings"
|
||||
|
||||
"hack-browser-data/internal/browingdata"
|
||||
"hack-browser-data/internal/item"
|
||||
"hack-browser-data/internal/log"
|
||||
"hack-browser-data/internal/utils/fileutil"
|
||||
"hack-browser-data/internal/utils/typeutil"
|
||||
)
|
||||
@@ -23,10 +22,14 @@ type firefox struct {
|
||||
itemPaths map[item.Item]string
|
||||
}
|
||||
|
||||
var (
|
||||
ErrProfilePathNotFound = errors.New("profile path not found")
|
||||
)
|
||||
|
||||
// New returns a new firefox instance.
|
||||
func New(name, storage, profilePath string, items []item.Item) ([]*firefox, error) {
|
||||
if !fileutil.FolderExists(profilePath) {
|
||||
return nil, fmt.Errorf("%s profile folder is not exist: %s", name, profilePath)
|
||||
return nil, ErrProfilePathNotFound
|
||||
}
|
||||
f := &firefox{
|
||||
name: name,
|
||||
@@ -36,10 +39,6 @@ func New(name, storage, profilePath string, items []item.Item) ([]*firefox, erro
|
||||
}
|
||||
multiItemPaths, err := f.getMultiItemPath(f.profilePath, f.items)
|
||||
if err != nil {
|
||||
if strings.Contains(err.Error(), "profile folder is not exist") {
|
||||
log.Error(err)
|
||||
return nil, nil
|
||||
}
|
||||
return nil, err
|
||||
}
|
||||
var firefoxList []*firefox
|
||||
|
||||
Reference in New Issue
Block a user