Skip to content

Database governance built for humans and agents — controlling changes and access across every major database.

chore: golangci-lint, enable more rules (#7877)

p0nyb4d268ecc49b
diff --git a/.golangci.yaml b/.golangci.yaml
index 7aed2f3e0c..c821375f74 100644
--- a/.golangci.yaml
+++ b/.golangci.yaml
@@ -84,6 +84,10 @@ linters-settings:
printf: # The name of the analyzer, run `go tool vet help` to see the list of all analyzers
funcs: # Run `go tool vet help printf` to see the full configuration of `printf`.
- common.Errorf
+ enable-all: true
+ disable:
+ - fieldalignment
+ - shadow
forbidigo:
forbid:
- 'fmt\.Errorf(# Please use errors\.Wrap\|Wrapf\|Errorf instead)?'
diff --git a/backend/api/v1/instance_service.go b/backend/api/v1/instance_service.go
index e631e5c5da..505daa7a86 100644
--- a/backend/api/v1/instance_service.go
+++ b/backend/api/v1/instance_service.go
@@ -381,8 +381,8 @@ func (s *InstanceService) syncSlowQueriesForProject(ctx context.Context, project
}
}
- if err != nil {
- return nil, status.Errorf(codes.Internal, "failed to sync slow queries for following instances: %s", err.Error())
+ if errs != nil {
+ return nil, status.Errorf(codes.Internal, "failed to sync slow queries for following instances: %s", errs.Error())
}
return &emptypb.Empty{}, nil
diff --git a/backend/api/v1/project_service.go b/backend/api/v1/project_service.go
index a7120a6f10..25799cc68b 100644
--- a/backend/api/v1/project_service.go
+++ b/backend/api/v1/project_service.go
@@ -416,10 +416,7 @@ func (s *ProjectService) UpdateProjectGitOpsInfo(ctx context.Context, request *v
ProjectResourceID: &project.ResourceID,
})
if err != nil {
- return nil, err
- }
- if err != nil {
- return nil, status.Errorf(codes.Internal, err.Error())
+ return nil, status.Errorf(codes.Internal, "failed to get repository, error %v", err.Error())
}
if repo == nil {
if !request.AllowMissing {
diff --git a/backend/component/activity/manager.go b/backend/component/activity/manager.go
index 5f5c5f1c9d..90ad29410d 100644
--- a/backend/component/activity/manager.go
+++ b/backend/component/activity/manager.go
@@ -541,21 +541,13 @@ func (m *Manager) getWebhookContext(ctx context.Context, activity *store.Activit
zap.Error(err))
return nil, err
}
- if newAssignee == nil {
- err := errors.Errorf("failed to post webhook event after changing the issue assignee, new assignee not found for ID %v", newID)
- log.Warn(err.Error(),
- zap.String("issue_name", meta.Issue.Title),
- zap.String("new_assignee_id", update.NewValue),
- zap.Error(err))
- return nil, err
- }
if oldAssignee != nil && newAssignee != nil {
title = fmt.Sprintf("Reassigned issue from %s to %s - %s", oldAssignee.Name, newAssignee.Name, meta.Issue.Title)
} else if newAssignee != nil {
title = fmt.Sprintf("Assigned issue to %s - %s", newAssignee.Name, meta.Issue.Title)
} else if oldAssignee != nil {
- title = fmt.Sprintf("Unassigned issue from %s - %s", newAssignee.Name, meta.Issue.Title)
+ title = fmt.Sprintf("Unassigned issue from %s - %s", oldAssignee.Name, meta.Issue.Title)
}
}
}
diff --git a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
index 7d52cb90fb..57e81f7bd9 100644
--- a/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
+++ b/backend/plugin/advisor/mssql/advisor_migration_compatibility.go
@@ -284,9 +284,6 @@ func (l *migrationCompatibilityChecker) EnterExecute_body(ctx *parser.Execute_bo
if firstArgument == nil {
return
}
- if firstArgument == nil {
- return
- }
if firstArgument.Execute_parameter() == nil {
return
}
diff --git a/backend/plugin/db/dm/sync.go b/backend/plugin/db/dm/sync.go
index 6e6d7d4b3f..5d5a813038 100644
--- a/backend/plugin/db/dm/sync.go
+++ b/backend/plugin/db/dm/sync.go
@@ -306,9 +306,6 @@ func getIndexes(txn *sql.Tx, schemaName string) (map[db.TableKey][]*storepb.Inde
index.Unique = unique == "UNIQUE"
indexKey := db.IndexKey{Schema: schemaName, Table: tableName, Index: index.Name}
index.Expressions = expressionsMap[indexKey]
- if err != nil {
- return nil, err
- }
key := db.TableKey{Schema: schemaName, Table: tableName}
indexMap[key] = append(indexMap[key], index)
diff --git a/backend/plugin/db/oracle/sync.go b/backend/plugin/db/oracle/sync.go
index a0a2744340..48c62e2dea 100644
--- a/backend/plugin/db/oracle/sync.go
+++ b/backend/plugin/db/oracle/sync.go
@@ -458,9 +458,6 @@ func getIndexes(txn *sql.Tx, schemaName string) (map[db.TableKey][]*storepb.Inde
index.Unique = unique == "UNIQUE"
indexKey := db.IndexKey{Schema: schemaName, Table: tableName, Index: index.Name}
index.Expressions = expressionsMap[indexKey]
- if err != nil {
- return nil, err
- }
key := db.TableKey{Schema: schemaName, Table: tableName}
indexMap[key] = append(indexMap[key], index)
diff --git a/backend/plugin/db/redshift/sync.go b/backend/plugin/db/redshift/sync.go
index f0941186e0..3743655c51 100644
--- a/backend/plugin/db/redshift/sync.go
+++ b/backend/plugin/db/redshift/sync.go
@@ -152,9 +152,6 @@ func (driver *Driver) SyncDBSchema(ctx context.Context) (*storepb.DatabaseSchema
return nil, common.Errorf(common.NotFound, "database %q not found", driver.databaseName)
}
- if err != nil {
- return nil, errors.Wrapf(err, "failed to get database connection for %q", driver.databaseName)
- }
txn, err := driver.db.BeginTx(ctx, nil)
if err != nil {
return nil, err
@@ -697,9 +694,6 @@ func getIndexes(txn *sql.Tx) (map[db.TableKey][]*storepb.IndexMetadata, error) {
index.Type = getIndexMethodType(statement)
index.Unique = node.Index.Unique
index.Expressions = node.Index.GetKeyNameList()
- if err != nil {
- return nil, err
- }
if primary.Valid && primary.Int32 == 1 {
index.Primary = true
}
diff --git a/backend/resources/postgres/postgres.go b/backend/resources/postgres/postgres.go
index 7ad34aa37c..e00d2e4a1b 100644
--- a/backend/resources/postgres/postgres.go
+++ b/backend/resources/postgres/postgres.go
@@ -178,7 +178,7 @@ func InitDB(pgBinDir, pgDataDir, pgUser string) error {
if err == nil {
break
}
- if err != nil && !os.IsNotExist(err) {
+ if !os.IsNotExist(err) {
return errors.Wrapf(err, "failed to check data directory path existence %q", path)
}
dirListToChown = append(dirListToChown, path)
diff --git a/backend/runner/plancheck/statement_type_executor.go b/backend/runner/plancheck/statement_type_executor.go
index db84e6ab61..31f57e6d1e 100644
--- a/backend/runner/plancheck/statement_type_executor.go
+++ b/backend/runner/plancheck/statement_type_executor.go
@@ -533,25 +533,6 @@ func mysqlStatementTypeCheck(statement string, charset string, collation string,
}, nil
}
- if err != nil {
- // nolint: nilerr
- return []*storepb.PlanCheckRunResult_Result{
- {
- Status: storepb.PlanCheckRunResult_Result_ERROR,
- Title: "Syntax error",
- Content: err.Error(),
- Code: 0,
- Report: &storepb.PlanCheckRunResult_Result_SqlReviewReport_{
- SqlReviewReport: &storepb.PlanCheckRunResult_Result_SqlReviewReport{
- Line: 0,
- Detail: "",
- Code: advisor.StatementSyntaxError.Int64(),
- },
- },
- },
- }, nil
- }
-
var results []*storepb.PlanCheckRunResult_Result
// Disallow CREATE/DROP DATABASE statements.
diff --git a/backend/runner/taskcheck/statement_type_executor.go b/backend/runner/taskcheck/statement_type_executor.go
index c9441d2498..9a15268646 100644
--- a/backend/runner/taskcheck/statement_type_executor.go
+++ b/backend/runner/taskcheck/statement_type_executor.go
@@ -280,19 +280,6 @@ func mysqlStatementTypeCheck(statement string, charset string, collation string,
}, nil
}
- if err != nil {
- // nolint: nilerr
- return []api.TaskCheckResult{
- {
- Status: api.TaskCheckStatusError,
- Namespace: api.AdvisorNamespace,
- Code: advisor.StatementSyntaxError.Int(),
- Title: "Syntax error",
- Content: err.Error(),
- },
- }, nil
- }
-
// Disallow CREATE/DROP DATABASE statements.
result = append(result, mysqlCreateAndDropDatabaseCheck(stmts)...)
diff --git a/backend/runner/taskrun/pitr_restore_executor.go b/backend/runner/taskrun/pitr_restore_executor.go
index 371fd069a0..e13d0098b1 100644
--- a/backend/runner/taskrun/pitr_restore_executor.go
+++ b/backend/runner/taskrun/pitr_restore_executor.go
@@ -132,9 +132,6 @@ func (exec *PITRRestoreExecutor) doBackupRestore(ctx context.Context, stores *st
if targetDatabase == nil {
return nil, errors.Wrapf(err, "target database %q not found in instance %q", *payload.DatabaseName, instance.Title)
}
- if err != nil {
- return nil, err
- }
log.Debug("Start database restore from backup...",
zap.String("source_instance", sourceDatabase.InstanceID),
zap.String("source_database", sourceDatabase.DatabaseName),
diff --git a/backend/server/issue.go b/backend/server/issue.go
index e90432d14f..446da0fc84 100644
--- a/backend/server/issue.go
+++ b/backend/server/issue.go
@@ -1225,9 +1225,6 @@ func (s *Server) getPipelineCreateForDatabaseSchemaAndDataUpdate(ctx context.Con
tableToSchemaGroupName[tableName] = fmt.Sprintf("databaseGroups/%s/schemaGroups/%s", databaseGroup.ResourceID, schemaGroup.ResourceID)
tableToTaskStatement[tableName] = &strings.Builder{}
}
- if err != nil {
- return nil, err
- }
// Placeholder is unique in the same database group parent, so we can use it as the key.
schemaGroupsToMatchedTableNames[schemaGroup.Placeholder] = matches
}
diff --git a/backend/store/task_check_run.go b/backend/store/task_check_run.go
index a160197e9b..578d14a2c5 100644
--- a/backend/store/task_check_run.go
+++ b/backend/store/task_check_run.go
@@ -159,9 +159,6 @@ func (s *Store) PatchTaskCheckRunStatus(ctx context.Context, patch *TaskCheckRun
); err != nil {
return err
}
- if err != nil {
- return err
- }
return tx.Commit()
}
diff --git a/backend/store/task_dag.go b/backend/store/task_dag.go
index ab08850411..da5eebc54a 100644
--- a/backend/store/task_dag.go
+++ b/backend/store/task_dag.go
@@ -47,9 +47,6 @@ func (s *Store) CreateTaskDAGV2(ctx context.Context, create *TaskDAGMessage) err
); err != nil {
return err
}
- if err != nil {
- return err
- }
return tx.Commit()
}