Changed error messages

This commit is contained in:
Jason Streifling 2024-02-22 15:23:29 +01:00
parent ebfe01069c
commit 6020b24e44
5 changed files with 27 additions and 13 deletions

View File

@ -19,15 +19,15 @@ func OpenDB(dbName string) (*DB, error) {
cfg.DBName = dbName cfg.DBName = dbName
cfg.User, cfg.Passwd, err = getCredentials() cfg.User, cfg.Passwd, err = getCredentials()
if err != nil { if err != nil {
return nil, fmt.Errorf("error: user credentials for DB could not be read: %v", err) return nil, fmt.Errorf("error reading user credentials for DB: %v", err)
} }
db.DB, err = sql.Open("mysql", cfg.FormatDSN()) db.DB, err = sql.Open("mysql", cfg.FormatDSN())
if err != nil { if err != nil {
return nil, fmt.Errorf("error: DB could not be opened: %v", err) return nil, fmt.Errorf("error opening DB: %v", err)
} }
if err = db.Ping(); err != nil { if err = db.Ping(); err != nil {
return nil, fmt.Errorf("error: DB could not be reached: %v", err) return nil, fmt.Errorf("error pinging DB: %v", err)
} }
return &db, nil return &db, nil

View File

@ -17,7 +17,7 @@ func getUsername() (string, error) {
fmt.Printf("DB Benutzer: ") fmt.Printf("DB Benutzer: ")
user, err = bufio.NewReader(os.Stdin).ReadString('\n') user, err = bufio.NewReader(os.Stdin).ReadString('\n')
if err != nil { if err != nil {
return fmt.Errorf("error: cmd/data/helpers.go getUsername bufio.NewReader().ReadString(): %v", err) return "", fmt.Errorf("error reading username: %v", err)
} }
} }
return strings.TrimSpace(user), nil return strings.TrimSpace(user), nil
@ -29,7 +29,7 @@ func getPassword() (string, error) {
fmt.Printf("DB Passwort: ") fmt.Printf("DB Passwort: ")
bytePass, err := term.ReadPassword(int(syscall.Stdin)) bytePass, err := term.ReadPassword(int(syscall.Stdin))
if err != nil { if err != nil {
return fmt.Errorf("error: cmd/data/helpers.go getPassword term.ReadPassword(): %v", err) return "", fmt.Errorf("error reading password: %v", err)
} }
fmt.Println() fmt.Println()
pass = strings.TrimSpace(string(bytePass)) pass = strings.TrimSpace(string(bytePass))
@ -40,12 +40,12 @@ func getPassword() (string, error) {
func getCredentials() (string, string, error) { func getCredentials() (string, string, error) {
user, err := getUsername() user, err := getUsername()
if err != nil { if err != nil {
return "", "", fmt.Errorf("error: cmd/data/helpers.go getCredentials getUsername(): %v", err) return "", "", fmt.Errorf("error getting username: %v", err)
} }
pass, err := getPassword() pass, err := getPassword()
if err != nil { if err != nil {
return "", "", fmt.Errorf("error: cmd/data/helpers.go getCredentials getPassword(): %v", err) return "", "", fmt.Errorf("error getting password: %v", err)
} }
return user, pass, nil return user, pass, nil

View File

@ -26,14 +26,14 @@ func NewFeed(title, link, desc string) *Feed {
func SaveFeed(feed *Feed, filename string) error { func SaveFeed(feed *Feed, filename string) error {
file, err := os.Create(filename) file, err := os.Create(filename)
if err != nil { if err != nil {
return fmt.Errorf("error cmd/feed/rss.go SaveFeed os.Create(): %v", err) return fmt.Errorf("error creating file %v: %v", filename, err)
} }
defer file.Close() defer file.Close()
encoder := gob.NewEncoder(file) encoder := gob.NewEncoder(file)
err = encoder.Encode(feed) err = encoder.Encode(feed)
if err != nil { if err != nil {
return fmt.Errorf("error cmd/feed/rss.go SaveFeed encoder.Encode(): %v", err) return fmt.Errorf("error encoding file %v: %v", filename, err)
} }
return nil return nil
@ -42,7 +42,7 @@ func SaveFeed(feed *Feed, filename string) error {
func OpenFeed(filename string) (*Feed, error) { func OpenFeed(filename string) (*Feed, error) {
file, err := os.Open(filename) file, err := os.Open(filename)
if err != nil { if err != nil {
return nil, fmt.Errorf("error cmd/feed/rss.go OpenFeed os.Open(): %v", err) return nil, fmt.Errorf("error opening file %v: %v", filename, err)
} }
defer file.Close() defer file.Close()
@ -50,7 +50,7 @@ func OpenFeed(filename string) (*Feed, error) {
decoder := gob.NewDecoder(file) decoder := gob.NewDecoder(file)
err = decoder.Decode(feed) err = decoder.Decode(feed)
if err != nil { if err != nil {
return nil, fmt.Errorf("error cmd/feed/rss.go OpenFeed decoder.Decode(): %v", err) return nil, fmt.Errorf("error decoding file %v: %v", filename, err)
} }
return feed, nil return feed, nil
@ -67,7 +67,7 @@ func AddToFeed(feed *Feed, title, desc, content string) error {
rss, err := feed.ToRss() rss, err := feed.ToRss()
if err != nil { if err != nil {
return fmt.Errorf("error cmd/feed/rss.go AddToFeed feed.ToRss(): %v", err) return fmt.Errorf("error converting feed to RSS: %v", err)
} }
fmt.Println(rss) fmt.Println(rss)

8
go.mod
View File

@ -5,8 +5,14 @@ go 1.22.0
require ( require (
github.com/go-sql-driver/mysql v1.7.1 github.com/go-sql-driver/mysql v1.7.1
github.com/gorilla/feeds v1.1.2 github.com/gorilla/feeds v1.1.2
github.com/microcosm-cc/bluemonday v1.0.26
github.com/yuin/goldmark v1.7.0 github.com/yuin/goldmark v1.7.0
golang.org/x/term v0.17.0 golang.org/x/term v0.17.0
) )
require golang.org/x/sys v0.17.0 // indirect require (
github.com/aymerick/douceur v0.2.0 // indirect
github.com/gorilla/css v1.0.0 // indirect
golang.org/x/net v0.17.0 // indirect
golang.org/x/sys v0.17.0 // indirect
)

8
go.sum
View File

@ -1,15 +1,23 @@
github.com/aymerick/douceur v0.2.0 h1:Mv+mAeH1Q+n9Fr+oyamOlAkUNPWPlA8PPGR0QAaYuPk=
github.com/aymerick/douceur v0.2.0/go.mod h1:wlT5vV2O3h55X9m7iVYN0TBM0NH/MmbLnd30/FjWUq4=
github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI= github.com/go-sql-driver/mysql v1.7.1 h1:lUIinVbN1DY0xBg0eMOzmmtGoHwWBbvnWubQUrtU8EI=
github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI= github.com/go-sql-driver/mysql v1.7.1/go.mod h1:OXbVy3sEdcQ2Doequ6Z5BW6fXNQTmx+9S1MCJN5yJMI=
github.com/gorilla/css v1.0.0 h1:BQqNyPTi50JCFMTw/b67hByjMVXZRwGha6wxVGkeihY=
github.com/gorilla/css v1.0.0/go.mod h1:Dn721qIggHpt4+EFCcTLTU/vk5ySda2ReITrtgBl60c=
github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw= github.com/gorilla/feeds v1.1.2 h1:pxzZ5PD3RJdhFH2FsJJ4x6PqMqbgFk1+Vez4XWBW8Iw=
github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y= github.com/gorilla/feeds v1.1.2/go.mod h1:WMib8uJP3BbY+X8Szd1rA5Pzhdfh+HCCAYT2z7Fza6Y=
github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE= github.com/kr/pretty v0.3.1 h1:flRD4NNwYAUpkphVc1HcthR4KEIFJ65n8Mw5qdRn3LE=
github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk= github.com/kr/pretty v0.3.1/go.mod h1:hoEshYVHaxMs3cyo3Yncou5ZscifuDolrwPKZanG3xk=
github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY= github.com/kr/text v0.2.0 h1:5Nx0Ya0ZqY2ygV366QzturHI13Jq95ApcVaJBhpS+AY=
github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE= github.com/kr/text v0.2.0/go.mod h1:eLer722TekiGuMkidMxC/pM04lWEeraHUUmBw8l2grE=
github.com/microcosm-cc/bluemonday v1.0.26 h1:xbqSvqzQMeEHCqMi64VAs4d8uy6Mequs3rQ0k/Khz58=
github.com/microcosm-cc/bluemonday v1.0.26/go.mod h1:JyzOCs9gkyQyjs+6h10UEVSe02CGwkhd72Xdqh78TWs=
github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8= github.com/rogpeppe/go-internal v1.9.0 h1:73kH8U+JUqXU8lRuOHeVHaa/SZPifC7BkcraZVejAe8=
github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs= github.com/rogpeppe/go-internal v1.9.0/go.mod h1:WtVeX8xhTBvf0smdhujwtBcq4Qrzq/fJaraNFVN+nFs=
github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA= github.com/yuin/goldmark v1.7.0 h1:EfOIvIMZIzHdB/R/zVrikYLPPwJlfMcNczJFMs1m6sA=
github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E= github.com/yuin/goldmark v1.7.0/go.mod h1:uzxRWxtg69N339t3louHJ7+O03ezfj6PlliRlaOzY1E=
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM=
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE=
golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y= golang.org/x/sys v0.17.0 h1:25cE3gD+tdBA7lp7QfhuV+rJiE9YXTcS3VG1SqssI/Y=
golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA= golang.org/x/sys v0.17.0/go.mod h1:/VUhepiaJMQUp4+oa/7Zr1D23ma6VTLIYjOOTFZPUcA=
golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U= golang.org/x/term v0.17.0 h1:mkTF7LCd6WGJNL3K1Ad7kwxNfYAW6a8a8QqtMblp/4U=