diff --git a/compose/commands/exporter.go b/compose/commands/exporter.go index c90b12a71..b4123193a 100644 --- a/compose/commands/exporter.go +++ b/compose/commands/exporter.go @@ -3,17 +3,16 @@ package commands import ( "context" "encoding/json" - "errors" "fmt" "github.com/cortezaproject/corteza-server/compose/service" "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/auth" "github.com/cortezaproject/corteza-server/pkg/cli" "github.com/cortezaproject/corteza-server/pkg/deinterfacer" + "github.com/cortezaproject/corteza-server/pkg/errors" "github.com/cortezaproject/corteza-server/pkg/handle" "github.com/cortezaproject/corteza-server/pkg/rbac" "github.com/cortezaproject/corteza-server/pkg/settings" - "github.com/cortezaproject/corteza-server/store" sysExporter "github.com/cortezaproject/corteza-server/system/exporter" sysService "github.com/cortezaproject/corteza-server/system/service" sysTypes "github.com/cortezaproject/corteza-server/system/types" diff --git a/compose/commands/importer.go b/compose/commands/importer.go index 3ed0a23f0..0c2695e7d 100644 --- a/compose/commands/importer.go +++ b/compose/commands/importer.go @@ -1,13 +1,12 @@ package commands import ( - "errors" "github.com/cortezaproject/corteza-server/compose/importer" "github.com/cortezaproject/corteza-server/compose/service" "github.com/cortezaproject/corteza-server/compose/types" "github.com/cortezaproject/corteza-server/pkg/auth" "github.com/cortezaproject/corteza-server/pkg/cli" - "github.com/cortezaproject/corteza-server/store" + "github.com/cortezaproject/corteza-server/pkg/errors" "github.com/spf13/cobra" "io" "os" diff --git a/compose/rest/record.go b/compose/rest/record.go index 54cec1b2e..066905c4a 100644 --- a/compose/rest/record.go +++ b/compose/rest/record.go @@ -490,8 +490,6 @@ func (ctrl Record) Exec(ctx context.Context, r *request.RecordExec) (interface{} default: return nil, fmt.Errorf("unknown procedure") } - - return nil, nil } func (ctrl *Record) TriggerScript(ctx context.Context, r *request.RecordTriggerScript) (interface{}, error) { diff --git a/compose/service/import_session.go b/compose/service/import_session.go index 233c65634..905a7e1df 100644 --- a/compose/service/import_session.go +++ b/compose/service/import_session.go @@ -29,7 +29,7 @@ func ImportSession() *importSession { } } -func (svc importSession) indexOf(userID, sessionID uint64) int { +func (svc *importSession) indexOf(userID, sessionID uint64) int { for i, r := range svc.records { if r.SessionID == sessionID && r.UserID == userID { return i diff --git a/compose/service/notification.go b/compose/service/notification.go index fa544cdd9..f791488d5 100644 --- a/compose/service/notification.go +++ b/compose/service/notification.go @@ -195,7 +195,7 @@ func (svc notification) procEmailAttachments(ctx context.Context, message *gomai for _, url := range aa { wg.Add(1) - go func() { + go func(url string) { defer wg.Done() _ = svc.recordAction( ctx, @@ -203,7 +203,7 @@ func (svc notification) procEmailAttachments(ctx context.Context, message *gomai NotificationActionAttachmentDownload, get(url), ) - }() + }(url) } wg.Wait() diff --git a/messaging/websocket/session.go b/messaging/websocket/session.go index 49253c0c1..90528a6b4 100644 --- a/messaging/websocket/session.go +++ b/messaging/websocket/session.go @@ -49,7 +49,7 @@ type ( } ) -func (Session) New(ctx context.Context, config *Config, conn *websocket.Conn) *Session { +func (*Session) New(ctx context.Context, config *Config, conn *websocket.Conn) *Session { s := &Session{ conn: conn, @@ -69,7 +69,7 @@ func (Session) New(ctx context.Context, config *Config, conn *websocket.Conn) *S return s } -func (sess Session) log(fields ...zapcore.Field) *zap.Logger { +func (sess *Session) log(fields ...zapcore.Field) *zap.Logger { return sess.logger.With(fields...) } diff --git a/pkg/corredor/service.go b/pkg/corredor/service.go index 39227f431..a2c88f6e0 100644 --- a/pkg/corredor/service.go +++ b/pkg/corredor/service.go @@ -587,8 +587,6 @@ func (svc *service) processIterator(script *Script) (ptr uintptr, err error) { default: return 0, fmt.Errorf("incompatible event type (%s) for iterator", i.EventType) } - - return } // Creates handler function for eventbus subsystem diff --git a/pkg/errors/error.go b/pkg/errors/error.go index fce75078f..a95b9a948 100644 --- a/pkg/errors/error.go +++ b/pkg/errors/error.go @@ -98,7 +98,7 @@ func (e *Error) Apply(ffn ...mfn) *Error { } // Is provided Is() method for equality checking with errors.Is -func (e Error) Is(target error) bool { +func (e *Error) Is(target error) bool { t, ok := target.(*Error) if !ok { return false diff --git a/pkg/errors/http_test.go b/pkg/errors/http_test.go index 082be489a..ae25b9a5d 100644 --- a/pkg/errors/http_test.go +++ b/pkg/errors/http_test.go @@ -5,7 +5,7 @@ import ( "os" ) -func ExampleSimpleErrorAsText() { +func Example_writeHttpPlain() { writeHttpPlain(os.Stdout, fmt.Errorf("dummy error")) // Output: @@ -13,14 +13,14 @@ func ExampleSimpleErrorAsText() { // -------------------------------------------------------------------------------- } -func ExampleSimpleErrorAsJson() { +func Example_writeHttpJSON() { writeHttpJSON(os.Stdout, fmt.Errorf("dummy error"), true) // Output: // {"error":{"message":"dummy error"}} } -func ExampleErrorAsText() { +func Example_writeHttpPlain_2() { err := New(0, "dummy error", Meta("a", "b"), Meta(&Error{}, "nope")) err.stack = nil // will not test the stack as file path & line numbers might change writeHttpPlain(os.Stdout, err) @@ -31,7 +31,7 @@ func ExampleErrorAsText() { // -------------------------------------------------------------------------------- } -func ExampleErrorAsJson() { +func Example_writeHttpJSON_2() { err := New(0, "dummy error", Meta("a", "b"), Meta(&Error{}, "nope")) err.stack = nil // will not test the stack as file path & line numbers might change writeHttpJSON(os.Stdout, err, false) diff --git a/pkg/healthcheck/check.go b/pkg/healthcheck/check.go index 4cd9d9b5a..1fbe94a28 100644 --- a/pkg/healthcheck/check.go +++ b/pkg/healthcheck/check.go @@ -81,7 +81,7 @@ func (rr results) String() string { return buf.String() } -func (rr results) WriteTo(w io.Writer) { +func (rr results) WriteTo(w io.Writer) (int64, error) { var ( p = func(f string, aa ...interface{}) { _, _ = fmt.Fprintf(w, f, aa...) @@ -103,6 +103,8 @@ func (rr results) WriteTo(w io.Writer) { p("\n") } + + return 0, nil } func (r *result) IsHealthy() bool { diff --git a/store/mysql/sql_typecasters.go b/store/mysql/sql_typecasters.go index 5d69ba198..2931b19d8 100644 --- a/store/mysql/sql_typecasters.go +++ b/store/mysql/sql_typecasters.go @@ -18,6 +18,4 @@ func fieldToColumnTypeCaster(field rdbms.ModuleFieldTypeDetector, ident string) default: return fmt.Sprintf("rv_%s.value ", ident), nil } - - return ident, nil } diff --git a/store/postgres/sql_typecasters.go b/store/postgres/sql_typecasters.go index 4b9710661..9669d8b14 100644 --- a/store/postgres/sql_typecasters.go +++ b/store/postgres/sql_typecasters.go @@ -18,6 +18,4 @@ func fieldToColumnTypeCaster(field rdbms.ModuleFieldTypeDetector, ident string) default: return fmt.Sprintf("rv_%s.value ", ident), nil } - - return ident, nil } diff --git a/store/rdbms/builder_test.go b/store/rdbms/builder_test.go index be01e5316..aaa28aaab 100644 --- a/store/rdbms/builder_test.go +++ b/store/rdbms/builder_test.go @@ -9,9 +9,10 @@ import ( func TestBuilder(t *testing.T) { var ( req = require.New(t) + cfg = &Config{} ) - upsert, err := UpsertBuilder("tbl", store.Payload{"c1": "v1", "c2": "v2"}, "c1") + upsert, err := UpsertBuilder(cfg, "tbl", store.Payload{"c1": "v1", "c2": "v2"}, "c1") req.NoError(err) sql, args, err := upsert.ToSql() req.NoError(err) diff --git a/store/rdbms/rdbms.go b/store/rdbms/rdbms.go index 7f4f6188d..14d8e2a18 100644 --- a/store/rdbms/rdbms.go +++ b/store/rdbms/rdbms.go @@ -187,7 +187,7 @@ func (s Store) tryToConnect(ctx context.Context, db *sqlx.DB) error { return err case <-time.After(to): // Wait before next try - return fmt.Errorf("timedout after %ds", to.Seconds()) + return fmt.Errorf("timedout after %.2fs", to.Seconds()) case <-ctx.Done(): return fmt.Errorf("connection cancelled") } diff --git a/store/sqlite3/sql_typecasters.go b/store/sqlite3/sql_typecasters.go index 1e4ae1c79..d9d2fc322 100644 --- a/store/sqlite3/sql_typecasters.go +++ b/store/sqlite3/sql_typecasters.go @@ -16,6 +16,4 @@ func fieldToColumnTypeCaster(field rdbms.ModuleFieldTypeDetector, ident string) default: return fmt.Sprintf("rv_%s.value ", ident), nil } - - return ident, nil } diff --git a/system/service/auth.go b/system/service/auth.go index a5d4464cd..39c502576 100644 --- a/system/service/auth.go +++ b/system/service/auth.go @@ -1023,7 +1023,7 @@ func (svc auth) autoPromote(ctx context.Context, u *types.User) (err error) { return nil } - return store.CreateRoleMember(ctx, svc.store, &types.RoleMember{roleID, u.ID}) + return store.CreateRoleMember(ctx, svc.store, &types.RoleMember{RoleID: roleID, UserID: u.ID}) }() return svc.recordAction(ctx, aam, AuthActionAutoPromote, err) diff --git a/system/service/sink_test.go b/system/service/sink_test.go index e9cc9cd17..e7cf108f8 100644 --- a/system/service/sink_test.go +++ b/system/service/sink_test.go @@ -2,7 +2,7 @@ package service import ( "bytes" - "errors" + "github.com/cortezaproject/corteza-server/pkg/errors" "io" "net/http" "reflect" @@ -216,7 +216,7 @@ func Test_sink_handleRequest(t *testing.T) { } got, err := svc.handleRequest(req) - if !errors.Is(err, tt.wantErr) { + if tt.wantErr != nil && err != nil && !errors.Is(err, tt.wantErr) { t.Errorf("handleRequest()\n"+ " error: %v\n"+ "wantErr: %v", err, tt.wantErr) diff --git a/tests/compose/record_exec_test.go b/tests/compose/record_exec_test.go index f70ec1e63..9c904c06a 100644 --- a/tests/compose/record_exec_test.go +++ b/tests/compose/record_exec_test.go @@ -133,9 +133,9 @@ func TestRecordExecOrganize(t *testing.T) { t.Logf("moving 'a' to position '6'") // Move a to the middle h.apiSendRecordExec(module.NamespaceID, module.ID, "organize", request.ProcedureArgs{ - {"recordID", rr["a"]}, - {"positionField", "position"}, - {"position", "6"}}). + {Name: "recordID", Value: rr["a"]}, + {Name: "positionField", Value: "position"}, + {Name: "position", Value: "6"}}). Status(http.StatusOK). Assert(helpers.AssertNoErrors). End() @@ -150,9 +150,9 @@ func TestRecordExecOrganize(t *testing.T) { t.Logf("moving 'i' to position '0'") // Move i to the beginning h.apiSendRecordExec(module.NamespaceID, module.ID, "organize", request.ProcedureArgs{ - {"recordID", rr["i"]}, - {"positionField", "position"}, - {"position", "0"}}). + {Name: "recordID", Value: rr["i"]}, + {Name: "positionField", Value: "position"}, + {Name: "position", Value: "0"}}). Status(http.StatusOK). Assert(helpers.AssertNoErrors). End() @@ -167,10 +167,10 @@ func TestRecordExecOrganize(t *testing.T) { t.Logf("moving 'b' to position '5'") // Move b to the 5th place h.apiSendRecordExec(module.NamespaceID, module.ID, "organize", request.ProcedureArgs{ - {"recordID", rr["b"]}, - {"filter", "category = 'CAT1'"}, - {"positionField", "position"}, - {"position", "5"}}). + {Name: "recordID", Value: rr["b"]}, + {Name: "filter", Value: "category = 'CAT1'"}, + {Name: "positionField", Value: "position"}, + {Name: "position", Value: "5"}}). Status(http.StatusOK). Assert(helpers.AssertNoErrors). End() @@ -185,9 +185,9 @@ func TestRecordExecOrganize(t *testing.T) { t.Logf("moving 'b' to category CAT2") // This will keep order of letters but move b to category-2 h.apiSendRecordExec(module.NamespaceID, module.ID, "organize", request.ProcedureArgs{ - {"recordID", rr["b"]}, - {"groupField", "category"}, - {"group", "CAT2"}}). + {Name: "recordID", Value: rr["b"]}, + {Name: "groupField", Value: "category"}, + {Name: "group", Value: "CAT2"}}). Status(http.StatusOK). Assert(helpers.AssertNoErrors). End()