Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

go: resolve various nilness issues #14803

Merged
merged 1 commit into from
Dec 18, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 1 addition & 3 deletions go/cmd/vtctldclient/command/vreplication/mount/mount.go
Original file line number Diff line number Diff line change
Expand Up @@ -143,9 +143,7 @@ func commandList(cmd *cobra.Command, args []string) error {
if err != nil {
return err
}
if err != nil {
return err
}

data, err := json.Marshal(resp)
if err != nil {
return err
Expand Down
5 changes: 2 additions & 3 deletions go/mysql/json/marshal.go
Original file line number Diff line number Diff line change
Expand Up @@ -169,13 +169,12 @@ func MarshalSQLValue(buf []byte) (*sqltypes.Value, error) {
if len(buf) == 0 {
buf = sqltypes.NullBytes
}

jsonVal, err := parser.ParseBytes(buf)
if err != nil {
return nil, err
}

newVal := sqltypes.MakeTrusted(querypb.Type_JSON, jsonVal.MarshalSQLTo(nil))
if err != nil {
return nil, err
}
return &newVal, nil
}
7 changes: 3 additions & 4 deletions go/test/endtoend/cluster/cluster_process.go
Original file line number Diff line number Diff line change
Expand Up @@ -765,19 +765,18 @@ func (cluster *LocalProcessCluster) populateVersionInfo() error {
return err
}

var versionRegex = regexp.MustCompile(`Version: ([0-9]+)\.([0-9]+)\.([0-9]+)`)
dbussink marked this conversation as resolved.
Show resolved Hide resolved

func GetMajorVersion(binaryName string) (int, error) {
version, err := exec.Command(binaryName, "--version").Output()
if err != nil {
return 0, err
}
versionRegex := regexp.MustCompile(`Version: ([0-9]+)\.([0-9]+)\.([0-9]+)`)
v := versionRegex.FindStringSubmatch(string(version))
if len(v) != 4 {
return 0, fmt.Errorf("could not parse server version from: %s", version)
}
if err != nil {
return 0, fmt.Errorf("could not parse server version from: %s", version)
}

return strconv.Atoi(v[1])
}

Expand Down
4 changes: 1 addition & 3 deletions go/vt/binlog/binlogplayer/dbclient.go
Original file line number Diff line number Diff line change
Expand Up @@ -183,8 +183,6 @@ func (dcr *dbClientImplWithSidecarDBReplacement) ExecuteFetchMulti(query string,
}
qps[i] = uq
}
if err != nil {
return nil, err
}

return dcr.dbClientImpl.ExecuteFetchMulti(strings.Join(qps, ";"), maxrows)
}
4 changes: 1 addition & 3 deletions go/vt/mysqlctl/mycnf.go
Original file line number Diff line number Diff line change
Expand Up @@ -178,9 +178,7 @@ func ReadMycnf(mycnf *Mycnf, waitTime time.Duration) (*Mycnf, error) {
defer f.Close()

buf := bufio.NewReader(f)
if err != nil {
return nil, err
}

mycnf.mycnfMap = make(map[string]string)
var lval, rval string
var parts [][]byte
Expand Down
3 changes: 2 additions & 1 deletion go/vt/mysqlctl/replication.go
Original file line number Diff line number Diff line change
Expand Up @@ -237,7 +237,8 @@ func (mysqld *Mysqld) IsSuperReadOnly() (bool, error) {
if err != nil {
return false, err
}
if err == nil && len(qr.Rows) == 1 {

if len(qr.Rows) == 1 {
sro := qr.Rows[0][0].ToString()
if sro == "1" || sro == "ON" {
return true, nil
Expand Down
9 changes: 2 additions & 7 deletions go/vt/schemadiff/schema.go
Original file line number Diff line number Diff line change
Expand Up @@ -1041,10 +1041,8 @@ func (s *Schema) getTableColumnNames(t *CreateTableEntity) (columnNames []*sqlpa
}

// getViewColumnNames returns the names of aliased columns returned by a given view.
func (s *Schema) getViewColumnNames(v *CreateViewEntity, schemaInformation *declarativeSchemaInformation) (
columnNames []*sqlparser.IdentifierCI,
err error,
) {
func (s *Schema) getViewColumnNames(v *CreateViewEntity, schemaInformation *declarativeSchemaInformation) ([]*sqlparser.IdentifierCI, error) {
var columnNames []*sqlparser.IdentifierCI
for _, node := range v.Select.GetColumns() {
switch node := node.(type) {
case *sqlparser.StarExpr:
Expand Down Expand Up @@ -1074,8 +1072,5 @@ func (s *Schema) getViewColumnNames(v *CreateViewEntity, schemaInformation *decl
}
}

if err != nil {
return nil, err
}
return columnNames, nil
}
2 changes: 1 addition & 1 deletion go/vt/sqlparser/parse_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -6346,7 +6346,7 @@ func parsePartial(r *bufio.Reader, readType []string, lineno int, fileName strin
if returnTypeNumber != -1 {
break
}
panic(fmt.Errorf("error reading file %s: line %d: %s - Expected keyword", fileName, lineno, err.Error()))
panic(fmt.Errorf("error reading file %s: line %d: Expected keyword", fileName, lineno))
}
input := ""
for {
Expand Down
14 changes: 6 additions & 8 deletions go/vt/zkctl/zkconf.go
Original file line number Diff line number Diff line change
Expand Up @@ -104,18 +104,16 @@ func MakeZooCfg(cnfFiles []string, cnf *ZkConfig, header string) (string, error)
for _, line := range strings.Split(header, "\n") {
fmt.Fprintf(&myTemplateSource, "## %v\n", strings.TrimSpace(line))
}
var dataErr error

for _, path := range cnfFiles {
data, dataErr := os.ReadFile(path)
if dataErr != nil {
data, err := os.ReadFile(path)
if err != nil {
continue
}

myTemplateSource.WriteString("## " + path + "\n")
myTemplateSource.Write(data)
}
if dataErr != nil {
return "", dataErr
}

myTemplateSource.WriteString("\n") // in case `data` did not end with a newline
for _, extra := range cnf.Extra {
Expand All @@ -126,9 +124,9 @@ func MakeZooCfg(cnfFiles []string, cnf *ZkConfig, header string) (string, error)
if err != nil {
return "", err
}

var cnfData strings.Builder
err = myTemplate.Execute(&cnfData, cnf)
if err != nil {
if err := myTemplate.Execute(&cnfData, cnf); err != nil {
return "", err
}
return cnfData.String(), nil
Expand Down
Loading