mirror of
https://github.com/mattermost/mattermost.git
synced 2026-05-28 04:35:04 -04:00
Fix return nil (#15330)
* Fix return nil A nil error is an interface having nil value but a non-nil type. This leads to unexpected errors in the code well-documented here: https://golang.org/doc/faq#nil_error We fix this by passing an additional parameter to handle it. Caught using https://github.com/dgryski/semgrep-go * Bring back auto-generated line
This commit is contained in:
parent
0eb63475a6
commit
94d09e1336
6 changed files with 257 additions and 253 deletions
|
|
@ -234,7 +234,7 @@ func (fs *FileStore) RemoveFile(name string) error {
|
|||
return errors.Wrap(err, "failed to remove file")
|
||||
}
|
||||
|
||||
return err
|
||||
return nil
|
||||
}
|
||||
|
||||
// startWatcher starts a watcher to monitor for external config file changes.
|
||||
|
|
|
|||
|
|
@ -231,11 +231,15 @@ func generateLayer(name, templateFile string) ([]byte, error) {
|
|||
}
|
||||
return fmt.Sprintf("(%s)", strings.Join(results, ", "))
|
||||
},
|
||||
"genResultsVars": func(results []string) string {
|
||||
"genResultsVars": func(results []string, withNilError bool) string {
|
||||
vars := []string{}
|
||||
for i, typeName := range results {
|
||||
if isError(typeName) {
|
||||
vars = append(vars, "err")
|
||||
if withNilError {
|
||||
vars = append(vars, "nil")
|
||||
} else {
|
||||
vars = append(vars, "err")
|
||||
}
|
||||
} else if i == 0 {
|
||||
vars = append(vars, "result")
|
||||
} else {
|
||||
|
|
|
|||
|
|
@ -53,14 +53,14 @@ func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinPa
|
|||
{{- if $element.Results | len | eq 0}}
|
||||
s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{else}}
|
||||
{{$element.Results | genResultsVars}} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{genResultsVars $element.Results false }} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{- if $element.Results | errorPresent }}
|
||||
if {{$element.Results | errorVar}} != nil {
|
||||
span.LogFields(spanlog.Error({{$element.Results | errorVar}}))
|
||||
ext.Error.Set(span, true)
|
||||
}
|
||||
{{end}}
|
||||
return {{ $element.Results | genResultsVars -}}
|
||||
{{end}}
|
||||
return {{ genResultsVars $element.Results false -}}
|
||||
{{end}}
|
||||
}
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -8,7 +8,7 @@ package retrylayer
|
|||
|
||||
import (
|
||||
"context"
|
||||
|
||||
|
||||
"github.com/lib/pq"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
|
@ -65,17 +65,17 @@ func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinPa
|
|||
{{else}}
|
||||
tries := 0
|
||||
for {
|
||||
{{$element.Results | genResultsVars}} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{genResultsVars $element.Results false }} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
if {{$element.Results | errorVar}} == nil {
|
||||
return {{$element.Results | genResultsVars}}
|
||||
return {{genResultsVars $element.Results true }}
|
||||
}
|
||||
if !isRepeatableError({{$element.Results | errorVar}}) {
|
||||
return {{$element.Results | genResultsVars}}
|
||||
return {{genResultsVars $element.Results false }}
|
||||
}
|
||||
tries++
|
||||
if tries >= 3 {
|
||||
{{$element.Results | errorVar}} = errors.Wrap({{$element.Results | errorVar}}, "giving up after 3 consecutive repeatable transaction failures")
|
||||
return {{$element.Results | genResultsVars}}
|
||||
return {{genResultsVars $element.Results false }}
|
||||
}
|
||||
}
|
||||
{{end}}
|
||||
|
|
|
|||
|
|
@ -9,7 +9,7 @@ package timerlayer
|
|||
import (
|
||||
"context"
|
||||
timemodule "time"
|
||||
|
||||
|
||||
"github.com/mattermost/mattermost-server/v5/einterfaces"
|
||||
"github.com/mattermost/mattermost-server/v5/model"
|
||||
"github.com/mattermost/mattermost-server/v5/store"
|
||||
|
|
@ -42,7 +42,7 @@ func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinPa
|
|||
{{if $element.Results | len | eq 0}}
|
||||
s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{else}}
|
||||
{{$element.Results | genResultsVars}} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{genResultsVars $element.Results false }} := s.{{$substoreName}}Store.{{$index}}({{$element.Params | joinParams}})
|
||||
{{end}}
|
||||
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
|
||||
if s.Root.Metrics != nil {
|
||||
|
|
@ -51,7 +51,7 @@ func (s *{{$.Name}}{{$substoreName}}Store) {{$index}}({{$element.Params | joinPa
|
|||
success = "true"
|
||||
}
|
||||
s.Root.Metrics.ObserveStoreMethodDuration("{{$substoreName}}Store.{{$index}}", success, elapsed)
|
||||
{{ with ($element.Results | genResultsVars) -}}
|
||||
{{ with (genResultsVars $element.Results false ) -}}
|
||||
}
|
||||
return {{ . }}
|
||||
{{- else -}}
|
||||
|
|
|
|||
File diff suppressed because it is too large
Load diff
Loading…
Reference in a new issue