From fe7f105daeef1bd9c0197c85d92fc19afa67bfe8 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 13:06:59 +0430 Subject: [PATCH 01/16] fix unhandled errors --- app_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app_test.go b/app_test.go index b20e0c455c..fcb623bdfb 100644 --- a/app_test.go +++ b/app_test.go @@ -499,17 +499,20 @@ func Test_App_Order(t *testing.T) { app := New() app.Get("/test", func(c *Ctx) error { - c.Write([]byte("1")) + _, err := c.Write([]byte("1")) + utils.AssertEqual(t, nil, err) return c.Next() }) app.All("/test", func(c *Ctx) error { - c.Write([]byte("2")) + _, err := c.Write([]byte("2")) + utils.AssertEqual(t, nil, err) return c.Next() }) app.Use(func(c *Ctx) error { - c.Write([]byte("3")) + _, err := c.Write([]byte("3")) + utils.AssertEqual(t, nil, err) return nil }) From 7f1028d7fc4b8f0d4b27ce77cc29523dcdc838ce Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 15:53:00 +0430 Subject: [PATCH 02/16] fix unhandled error in cache package test --- middleware/cache/cache_test.go | 6 +++++- 1 file changed, 5 insertions(+), 1 deletion(-) diff --git a/middleware/cache/cache_test.go b/middleware/cache/cache_test.go index 4c7e155a36..f991d24b0a 100644 --- a/middleware/cache/cache_test.go +++ b/middleware/cache/cache_test.go @@ -5,6 +5,7 @@ package cache import ( "bytes" "fmt" + "io" "io/ioutil" "math" "net/http" @@ -126,7 +127,10 @@ func Test_Cache_WithSeveralRequests(t *testing.T) { rsp, err := app.Test(httptest.NewRequest(http.MethodGet, fmt.Sprintf("/%d", id), nil)) utils.AssertEqual(t, nil, err) - defer rsp.Body.Close() + defer func(Body io.ReadCloser) { + err := Body.Close() + utils.AssertEqual(t, nil, err) + }(rsp.Body) idFromServ, err := ioutil.ReadAll(rsp.Body) utils.AssertEqual(t, nil, err) From bf387fae1698ed6536620c109d96eb6c184e2c65 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 16:05:19 +0430 Subject: [PATCH 03/16] omit variable type --- internal/go-ole/connect.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/internal/go-ole/connect.go b/internal/go-ole/connect.go index b2ac2ec67a..b910f0e329 100644 --- a/internal/go-ole/connect.go +++ b/internal/go-ole/connect.go @@ -44,8 +44,8 @@ func (c *Connection) Release() { // Load COM object from list of programIDs or strings. func (c *Connection) Load(names ...string) (errors []error) { - var tempErrors []error = make([]error, len(names)) - var numErrors int = 0 + var tempErrors = make([]error, len(names)) + var numErrors = 0 for _, name := range names { err := c.Create(name) if err != nil { From d09213bfa26bbc331619d755d3ffd3c43c560070 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 16:07:15 +0430 Subject: [PATCH 04/16] omit variable type --- middleware/session/session_test.go | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/middleware/session/session_test.go b/middleware/session/session_test.go index 4afef2458d..19bf121fa0 100644 --- a/middleware/session/session_test.go +++ b/middleware/session/session_test.go @@ -127,9 +127,9 @@ func Test_Session_Types(t *testing.T) { Name: "John", } // set value - var vbool bool = true - var vstring string = "str" - var vint int = 13 + var vbool = true + var vstring = "str" + var vint = 13 var vint8 int8 = 13 var vint16 int16 = 13 var vint32 int32 = 13 From 14b6646bbf66c7d1726975f7d8b5b32cb6440794 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 16:10:52 +0430 Subject: [PATCH 05/16] rename variable because collide with the imported package name --- internal/schema/decoder.go | 12 ++++++------ 1 file changed, 6 insertions(+), 6 deletions(-) diff --git a/internal/schema/decoder.go b/internal/schema/decoder.go index 9d44822202..b63c45e1dc 100644 --- a/internal/schema/decoder.go +++ b/internal/schema/decoder.go @@ -74,19 +74,19 @@ func (d *Decoder) Decode(dst interface{}, src map[string][]string) error { } v = v.Elem() t := v.Type() - errors := MultiError{} + multiError := MultiError{} for path, values := range src { if parts, err := d.cache.parsePath(path, t); err == nil { if err = d.decode(v, path, parts, values); err != nil { - errors[path] = err + multiError[path] = err } } else if !d.ignoreUnknownKeys { - errors[path] = UnknownKeyError{Key: path} + multiError[path] = UnknownKeyError{Key: path} } } - errors.merge(d.checkRequired(t, src)) - if len(errors) > 0 { - return errors + multiError.merge(d.checkRequired(t, src)) + if len(multiError) > 0 { + return multiError } return nil } From 1c45f7e821298a53858c0725f57594bb0b1c2c08 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 26 Aug 2022 16:27:12 +0430 Subject: [PATCH 06/16] handle file error on closing --- internal/gopsutil/common/common.go | 15 +++++++++++++-- 1 file changed, 13 insertions(+), 2 deletions(-) diff --git a/internal/gopsutil/common/common.go b/internal/gopsutil/common/common.go index dc7a927b26..5c7adace0e 100644 --- a/internal/gopsutil/common/common.go +++ b/internal/gopsutil/common/common.go @@ -13,6 +13,7 @@ import ( "errors" "fmt" "io/ioutil" + "log" "net/url" "os" "os/exec" @@ -122,7 +123,12 @@ func ReadLinesOffsetN(filename string, offset uint, n int) ([]string, error) { if err != nil { return []string{""}, err } - defer f.Close() + defer func(f *os.File) { + err := f.Close() + if err != nil { + log.Fatalln(err) + } + }(f) var ret []string @@ -204,7 +210,12 @@ func ReadInts(filename string) ([]int64, error) { if err != nil { return []int64{}, err } - defer f.Close() + defer func(f *os.File) { + err := f.Close() + if err != nil { + log.Fatalln(err) + } + }(f) var ret []int64 From 89bf878c534d1f67094ee0aff1952f09a758589c Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Sun, 28 Aug 2022 10:24:54 +0430 Subject: [PATCH 07/16] fix unhandled in common_linux.go --- internal/gopsutil/common/common_linux.go | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/internal/gopsutil/common/common_linux.go b/internal/gopsutil/common/common_linux.go index 9234f767d7..a89c8e28ac 100644 --- a/internal/gopsutil/common/common_linux.go +++ b/internal/gopsutil/common/common_linux.go @@ -6,6 +6,7 @@ package common import ( "context" "fmt" + "log" "os" "os/exec" "path/filepath" @@ -37,7 +38,12 @@ func NumProcs() (uint64, error) { if err != nil { return 0, err } - defer f.Close() + defer func(f *os.File) { + err := f.Close() + if err != nil { + log.Fatalln(err) + } + }(f) list, err := f.Readdirnames(-1) if err != nil { From 08a925670d778490b24f43ee2d8f2c3085ac42c2 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Mon, 29 Aug 2022 15:25:25 +0430 Subject: [PATCH 08/16] fix unhandled errors in helpers_test.go --- helpers_test.go | 15 ++++++++++----- 1 file changed, 10 insertions(+), 5 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index 7b45540de7..f1bfbb2ec8 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -22,7 +22,8 @@ func Test_Utils_ETag(t *testing.T) { t.Run("Not Status OK", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) c.Status(201) setETag(c, false) utils.AssertEqual(t, "", string(c.Response().Header.Peek(HeaderETag))) @@ -38,7 +39,8 @@ func Test_Utils_ETag(t *testing.T) { t.Run("Has HeaderIfNoneMatch", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) c.Request().Header.Set(HeaderIfNoneMatch, `"13-1831710635"`) setETag(c, false) utils.AssertEqual(t, 304, c.Response().StatusCode()) @@ -49,7 +51,8 @@ func Test_Utils_ETag(t *testing.T) { t.Run("No HeaderIfNoneMatch", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) setETag(c, false) utils.AssertEqual(t, `"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag))) }) @@ -60,7 +63,8 @@ func Benchmark_Utils_ETag(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(b, nil, err) for n := 0; n < b.N; n++ { setETag(c, false) } @@ -73,7 +77,8 @@ func Test_Utils_ETag_Weak(t *testing.T) { t.Run("Set Weak", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) setETag(c, true) utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag))) }) From 038315df1e3c9ca17349ebd1670ede564d43efd3 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Tue, 30 Aug 2022 10:51:02 +0430 Subject: [PATCH 09/16] fix unhandled errors in listen_test.go --- listen_test.go | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/listen_test.go b/listen_test.go index 11d1908bd4..13f42e19d3 100644 --- a/listen_test.go +++ b/listen_test.go @@ -166,12 +166,18 @@ func captureOutput(f func()) string { go func() { var buf bytes.Buffer wg.Done() - io.Copy(&buf, reader) + _, err := io.Copy(&buf, reader) + if err != nil { + panic(err) + } out <- buf.String() }() wg.Wait() f() - writer.Close() + err = writer.Close() + if err != nil { + panic(err) + } return <-out } From e5b8dad14642a598f161df96a9fb7f31a36eea22 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Tue, 30 Aug 2022 10:52:08 +0430 Subject: [PATCH 10/16] remove unused parameter in emptyHandler method --- listen_test.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/listen_test.go b/listen_test.go index 13f42e19d3..978e953a4d 100644 --- a/listen_test.go +++ b/listen_test.go @@ -250,6 +250,6 @@ func Test_App_print_Route_with_group(t *testing.T) { utils.AssertEqual(t, true, strings.Contains(printRoutesMessage, "/v1/test/fiber/*")) } -func emptyHandler(c *Ctx) error { +func emptyHandler(_ *Ctx) error { return nil } From 92e6920fff506a16981cea2ccb702cf6dd1f1924 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Thu, 1 Sep 2022 16:58:19 +0430 Subject: [PATCH 11/16] refactor path.go --- path.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/path.go b/path.go index db2818dd00..ca41f45969 100644 --- a/path.go +++ b/path.go @@ -61,7 +61,7 @@ const ( paramConstraintDataSeparator byte = ',' // separator of datas of type constraint for a parameter ) -// parameter constraint types +// TypeConstraint parameter constraint types type TypeConstraint int16 type Constraint struct { @@ -260,7 +260,7 @@ func (routeParser *routeParser) analyseParameterPart(pattern string) (string, *r // Check has constraint var constraints []*Constraint - if hasConstraint := (parameterConstraintStart != -1 && parameterConstraintEnd != -1); hasConstraint { + if hasConstraint := parameterConstraintStart != -1 && parameterConstraintEnd != -1; hasConstraint { constraintString := pattern[parameterConstraintStart+1 : parameterConstraintEnd] userconstraints := splitNonEscaped(constraintString, string(parameterConstraintSeparatorChars)) constraints = make([]*Constraint, 0, len(userconstraints)) From 3086fd2f6c53fd1edd4def45d88afc6f7475b52d Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Thu, 1 Sep 2022 17:04:25 +0430 Subject: [PATCH 12/16] unhandled error in hooks test --- hooks_test.go | 16 ++++++++++------ 1 file changed, 10 insertions(+), 6 deletions(-) diff --git a/hooks_test.go b/hooks_test.go index 5a800920d2..5ed9d82145 100644 --- a/hooks_test.go +++ b/hooks_test.go @@ -42,7 +42,8 @@ func Test_Hook_OnName(t *testing.T) { defer bytebufferpool.Put(buf) app.Hooks().OnName(func(r Route) error { - buf.WriteString(r.Name) + _, err := buf.WriteString(r.Name) + utils.AssertEqual(t, nil, err) return nil }) @@ -84,8 +85,8 @@ func Test_Hook_OnGroup(t *testing.T) { defer bytebufferpool.Put(buf) app.Hooks().OnGroup(func(g Group) error { - buf.WriteString(g.Prefix) - + _, err := buf.WriteString(g.Prefix) + utils.AssertEqual(t, nil, err) return nil }) @@ -104,7 +105,8 @@ func Test_Hook_OnGroupName(t *testing.T) { defer bytebufferpool.Put(buf) app.Hooks().OnGroupName(func(g Group) error { - buf.WriteString(g.name) + _, err := buf.WriteString(g.name) + utils.AssertEqual(t, nil, err) return nil }) @@ -143,7 +145,8 @@ func Test_Hook_OnShutdown(t *testing.T) { defer bytebufferpool.Put(buf) app.Hooks().OnShutdown(func() error { - buf.WriteString("shutdowning") + _, err := buf.WriteString("shutdowning") + utils.AssertEqual(t, nil, err) return nil }) @@ -163,7 +166,8 @@ func Test_Hook_OnListen(t *testing.T) { defer bytebufferpool.Put(buf) app.Hooks().OnListen(func() error { - buf.WriteString("ready") + _, err := buf.WriteString("ready") + utils.AssertEqual(t, nil, err) return nil }) From 8b466c3e281cb127d0c464b4231895bda88d202e Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 2 Sep 2022 12:25:13 +0430 Subject: [PATCH 13/16] fix unhandled errors in app_test.go --- app_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/app_test.go b/app_test.go index fcb623bdfb..abd858a7e6 100644 --- a/app_test.go +++ b/app_test.go @@ -1136,7 +1136,8 @@ func Benchmark_App_ETag(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.Send([]byte("Hello, World!")) + err := c.Send([]byte("Hello, World!")) + utils.AssertEqual(b, nil, err) for n := 0; n < b.N; n++ { setETag(c, false) } @@ -1148,7 +1149,8 @@ func Benchmark_App_ETag_Weak(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.Send([]byte("Hello, World!")) + err := c.Send([]byte("Hello, World!")) + utils.AssertEqual(b, nil, err) for n := 0; n < b.N; n++ { setETag(c, true) } @@ -1378,7 +1380,8 @@ func Test_App_New_Test_Parallel(t *testing.T) { t.Run("Test_App_New_Test_Parallel_2", func(t *testing.T) { t.Parallel() app := New(Config{Immutable: true}) - app.Test(httptest.NewRequest("GET", "/", nil)) + _, err := app.Test(httptest.NewRequest("GET", "/", nil)) + utils.AssertEqual(t, nil, err) }) } From a125a5f0c11ff5e280ba0d445ccd536b3e19b0e7 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Fri, 2 Sep 2022 12:38:04 +0430 Subject: [PATCH 14/16] fix unhandled errors in ctx_test.go --- ctx_test.go | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/ctx_test.go b/ctx_test.go index 31f47e7a29..caf037877d 100644 --- a/ctx_test.go +++ b/ctx_test.go @@ -755,35 +755,42 @@ func Test_Ctx_Format(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) c.Request().Header.Set(HeaderAccept, MIMETextPlain) - c.Format([]byte("Hello, World!")) + err := c.Format([]byte("Hello, World!")) + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, "Hello, World!", string(c.Response().Body())) c.Request().Header.Set(HeaderAccept, MIMETextHTML) - c.Format("Hello, World!") + err = c.Format("Hello, World!") + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, "

Hello, World!

", string(c.Response().Body())) c.Request().Header.Set(HeaderAccept, MIMEApplicationJSON) - c.Format("Hello, World!") + err = c.Format("Hello, World!") + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, `"Hello, World!"`, string(c.Response().Body())) c.Request().Header.Set(HeaderAccept, MIMETextPlain) - c.Format(complex(1, 1)) + err = c.Format(complex(1, 1)) + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, "(1+1i)", string(c.Response().Body())) c.Request().Header.Set(HeaderAccept, MIMEApplicationXML) - c.Format("Hello, World!") + err = c.Format("Hello, World!") + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, `Hello, World!`, string(c.Response().Body())) - err := c.Format(complex(1, 1)) + err = c.Format(complex(1, 1)) utils.AssertEqual(t, true, err != nil) c.Request().Header.Set(HeaderAccept, MIMETextPlain) - c.Format(Map{}) + err = c.Format(Map{}) + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, "map[]", string(c.Response().Body())) type broken string c.Request().Header.Set(HeaderAccept, "broken/accept") - c.Format(broken("Hello, World!")) + err = c.Format(broken("Hello, World!")) + utils.AssertEqual(t, nil, err) utils.AssertEqual(t, `Hello, World!`, string(c.Response().Body())) } @@ -3137,8 +3144,8 @@ func Test_Ctx_Get_Location_From_Route_name(t *testing.T) { utils.AssertEqual(t, nil, err) utils.AssertEqual(t, "/user/fiber", location) }) - - t.Run("case sensitive",func(t *testing.T) { + + t.Run("case sensitive", func(t *testing.T) { app := New(Config{CaseSensitive: true}) c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) From 81a0bc570387ab97df54940d747a893a25c8c54a Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Sun, 4 Sep 2022 11:13:43 +0430 Subject: [PATCH 15/16] =?UTF-8?q?=E2=9C=A8=20fix=20unhandled=20errors=20in?= =?UTF-8?q?=20helpers=5Ftest.go?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- helpers_test.go | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/helpers_test.go b/helpers_test.go index e72e727256..03c1e687a9 100644 --- a/helpers_test.go +++ b/helpers_test.go @@ -84,7 +84,8 @@ func Test_Utils_ETag_Weak(t *testing.T) { t.Run("Match Weak ETag", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635"`) setETag(c, true) utils.AssertEqual(t, 304, c.Response().StatusCode()) @@ -95,7 +96,8 @@ func Test_Utils_ETag_Weak(t *testing.T) { t.Run("Not Match Weak ETag", func(t *testing.T) { c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(t, nil, err) c.Request().Header.Set(HeaderIfNoneMatch, `W/"13-1831710635xx"`) setETag(c, true) utils.AssertEqual(t, `W/"13-1831710635"`, string(c.Response().Header.Peek(HeaderETag))) @@ -135,7 +137,8 @@ func Benchmark_Utils_ETag_Weak(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - c.SendString("Hello, World!") + err := c.SendString("Hello, World!") + utils.AssertEqual(b, nil, err) for n := 0; n < b.N; n++ { setETag(c, true) } From cec4b837112b8495ac0fbdc14f4e567e77ba25f6 Mon Sep 17 00:00:00 2001 From: Kamandlou Date: Mon, 5 Sep 2022 10:06:48 +0430 Subject: [PATCH 16/16] revert app_test.go --- app_test.go | 6 ++---- 1 file changed, 2 insertions(+), 4 deletions(-) diff --git a/app_test.go b/app_test.go index abd858a7e6..d186193ae3 100644 --- a/app_test.go +++ b/app_test.go @@ -1136,8 +1136,7 @@ func Benchmark_App_ETag(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - err := c.Send([]byte("Hello, World!")) - utils.AssertEqual(b, nil, err) + c.Send([]byte("Hello, World!")) for n := 0; n < b.N; n++ { setETag(c, false) } @@ -1149,8 +1148,7 @@ func Benchmark_App_ETag_Weak(b *testing.B) { app := New() c := app.AcquireCtx(&fasthttp.RequestCtx{}) defer app.ReleaseCtx(c) - err := c.Send([]byte("Hello, World!")) - utils.AssertEqual(b, nil, err) + c.Send([]byte("Hello, World!")) for n := 0; n < b.N; n++ { setETag(c, true) }