commit 3199a7d96160c521a6c5f9c3de08a1f40d60d4c2
parent c1f32c38c58b591706989ef8091e143d882d3776
Author: Petr Razumov <razumov.petr@wb.ru>
Date: Tue, 4 Apr 2023 15:41:26 +0300
fix: check for errors
Diffstat:
9 files changed, 71 insertions(+), 22 deletions(-)
diff --git a/cmd/idecctl/main.go b/cmd/idecctl/main.go
@@ -107,7 +107,10 @@ Options:
db := open_db(*db_opt)
db.Lock()
defer db.Unlock()
- db.LoadIndex()
+ if err := db.LoadIndex(); err != nil {
+ fmt.Printf("Can not load index: %s\n", err)
+ os.Exit(1)
+ }
for _, v := range db.Idx.List {
if echo != "" {
mi := db.Idx.Hash[v]
@@ -196,6 +199,10 @@ Options:
}
return true
})
+ if err != nil {
+ fmt.Printf("Error: %s\n", err)
+ os.Exit(1)
+ }
fmt.Printf("%d lines... %d dups...\n", nr, dup)
if dup == 0 {
os.Exit(0)
@@ -392,7 +399,10 @@ Options:
}
case "sort":
db := open_db(*db_opt)
- db.LoadIndex()
+ if err := db.LoadIndex(); err != nil {
+ fmt.Printf("Can not load index: %s\n", err)
+ os.Exit(1)
+ }
scanner := bufio.NewScanner(os.Stdin)
var mm []*ii.Msg
for scanner.Scan() {
diff --git a/cmd/idecd/main.go b/cmd/idecd/main.go
@@ -24,7 +24,11 @@ func open_db(path string) *ii.DB {
}
func PointMsg(edb *ii.EDB, db *ii.DB, udb *ii.UDB, pauth string, tmsg string) string {
- udb.LoadUsers()
+ err := udb.LoadUsers()
+ if err != nil {
+ ii.Error.Printf("Error loading users: %s", err)
+ return err.Error()
+ }
if !udb.Access(pauth) {
ii.Info.Printf("Access denied for pauth: %s", pauth)
@@ -165,7 +169,11 @@ func main() {
var pauth, tmsg string
switch r.Method {
case "GET":
- udb.LoadUsers()
+ err := udb.LoadUsers()
+ if err != nil {
+ ii.Error.Printf("Error loaging users: %s", err)
+ return
+ }
args := strings.Split(r.URL.Path[9:], "/")
if len(args) >= 3 && args[1] == "u" {
diff --git a/cmd/idecd/web.go b/cmd/idecd/web.go
@@ -268,7 +268,9 @@ func www_avatar(ctx *WebContext, w http.ResponseWriter, r *http.Request, user st
}
b64 := base64.URLEncoding.EncodeToString([]byte(ava))
ii.Trace.Printf("New avatar for %s: %s", ctx.User.Name, b64)
- ctx.User.Tags.Add("avatar/" + b64)
+ if err := ctx.User.Tags.Add("avatar/" + b64); err != nil {
+ return err
+ }
}
if err := ctx.www.udb.Edit(ctx.User); err != nil {
ii.Error.Printf("Error saving avatar: " + user)
@@ -444,7 +446,9 @@ func www_topics(ctx *WebContext, w http.ResponseWriter, r *http.Request, page in
db.Sync.RLock()
defer db.Sync.RUnlock()
- db.LoadIndex()
+ if err := db.LoadIndex(); err != nil {
+ return err
+ }
for _, t := range topicsIds {
topic := Topic{}
topic.Ids = t
@@ -637,7 +641,9 @@ func www_new(ctx *WebContext, w http.ResponseWriter, r *http.Request) error {
m.From = ctx.User.Name
m.Addr = fmt.Sprintf("%s,%d", ctx.www.db.Name, ctx.User.Id)
if repto != "" {
- m.Tags.Add("repto/" + repto)
+ if err := m.Tags.Add("repto/" + repto); err != nil {
+ return err
+ }
}
if id != "" {
om := ctx.www.db.Get(id)
@@ -684,7 +690,9 @@ func www_reply(ctx *WebContext, w http.ResponseWriter, r *http.Request, quote bo
msg := *m
msg.To = msg.From
msg.Subj = "Re: " + strings.TrimPrefix(msg.Subj, "Re: ")
- msg.Tags.Add("repto/" + id)
+ if err := msg.Tags.Add("repto/" + id); err != nil {
+ return err
+ }
if quote {
msg.Text = msg_quote(msg.Text, msg.From)
} else {
@@ -919,7 +927,10 @@ func WebInit(www *WWW) {
func handleErr(ctx *WebContext, w http.ResponseWriter, err error) {
ctx.Error = err.Error()
ctx.Template = "error.tpl"
- ctx.www.tpl.ExecuteTemplate(w, "error.tpl", ctx)
+ if err := ctx.www.tpl.ExecuteTemplate(w, "error.tpl", ctx); err != nil {
+ // FIXME: correctly handle this error
+ panic(err)
+ }
}
func handleWWW(www *WWW, w http.ResponseWriter, r *http.Request) {
@@ -929,8 +940,11 @@ func handleWWW(www *WWW, w http.ResponseWriter, r *http.Request) {
ctx.www = www
ctx.Sysname = www.db.Name
ctx.Host = www.Host
- www.udb.LoadUsers()
- err := _handleWWW(&ctx, w, r)
+ err := www.udb.LoadUsers()
+ if err != nil {
+ handleErr(&ctx, w, err)
+ }
+ err = _handleWWW(&ctx, w, r)
if err != nil {
handleErr(&ctx, w, err)
}
diff --git a/cmd/idecgmi/main.go b/cmd/idecgmi/main.go
@@ -135,7 +135,9 @@ Options:
db := open_db(*db_opt)
db.Lock()
defer db.Unlock()
- db.LoadIndex()
+ if err := db.LoadIndex(); err != nil {
+ return
+ }
scanner := bufio.NewScanner(os.Stdin)
var mis []*ii.Msg
diff --git a/contrib/secure/main.go b/contrib/secure/main.go
@@ -64,5 +64,7 @@ func main() {
log.Printf("listen-addr=%s upstream-url=%s", srv.Addr, u.String())
- srv.ListenAndServeTLS("", "")
+ if err := srv.ListenAndServeTLS("", ""); err != nil {
+ log.Fatal(err)
+ }
}
diff --git a/ii/db.go b/ii/db.go
@@ -196,8 +196,13 @@ func (db *DB) _CreateIndex() error {
if v, _ := msg.Tag("access"); v == "blacklist" {
ioff = -1
}
- fidx.WriteString(fmt.Sprintf("%s:%s:%d:%s:%s:%s\n",
+
+ _, err := fidx.WriteString(fmt.Sprintf("%s:%s:%d:%s:%s:%s\n",
msg.MsgId, msg.Echo, ioff, msg.To, msg.From, repto))
+ if err != nil {
+ // FIXME: handle this error
+ panic(err)
+ }
off += int64(len(line) + 1)
return true
})
@@ -699,7 +704,10 @@ func (db *DB) GetTopics(mi []*MsgInfo) map[string][]string {
intopic := make(map[string]string)
topics := make(map[string][]string)
- db.LoadIndex()
+ if err := db.LoadIndex(); err != nil {
+ // FIXME: handle this error
+ panic(err)
+ }
for _, m := range mi {
if _, ok := intopic[m.Id]; ok {
continue
@@ -778,7 +786,9 @@ func (db *DB) Edit(m *Msg) error {
// to store it in DB. While loading index, blacklisted messages
// are marked by negative Off field (-1).
func (db *DB) Blacklist(m *Msg) error {
- m.Tags.Add("access/blacklist")
+ if err := m.Tags.Add("access/blacklist"); err != nil {
+ return err
+ }
return db.Edit(m)
//db.Sync.Lock()
diff --git a/ii/msg.go b/ii/msg.go
@@ -129,7 +129,9 @@ func DecodeMsgline(msg string, enc bool) (*Msg, error) {
if strings.HasPrefix(repto, "@repto:") {
start += 1
repto = strings.Trim(strings.Split(repto, ":")[1], " ")
- m.Tags.Add("repto/" + repto)
+ if err := m.Tags.Add("repto/" + repto); err != nil {
+ return nil, err
+ }
Trace.Printf("Add repto tag: %s", repto)
}
for i := start; i < len(text); i++ {
diff --git a/ii/msg_test.go b/ii/msg_test.go
@@ -18,10 +18,9 @@ var Test_msg string = "a5OX4lC8uB8OIzzzGQ5B:" +
"LouINCd0L4sINC60L7QvdC10YfQvdC+LCDQsdCw0LPQuCDQvNC+0LPRg9GCINCx0YvRgtGMLg=="
func TestParse(t *testing.T) {
- var m *Msg
- m, _ = DecodeBundle(Test_msg)
- if m == nil {
- t.Error("Can not decode msg")
+ m, err := DecodeBundle(Test_msg)
+ if err != nil {
+ t.Errorf("Can not decode msg: %s", err)
}
text := m.MsgId + ":" + m.Encode()
decoded, _ := base64.StdEncoding.DecodeString(text)
diff --git a/ii/net.go b/ii/net.go
@@ -143,7 +143,9 @@ func (n *Node) Fetcher(db *DB, Echo string, limit int, wait *sync.WaitGroup, con
}); err != nil {
return
}
- n.Store(db, res)
+
+ // FIXME: handle this error
+ _ = n.Store(db, res)
}
// Do not run more then MaxConnections goroutines in the same time