Layer generators error return type fix (#14526)

This commit is contained in:
Eli Yukelzon
2020-05-11 12:37:02 +03:00
committed by GitHub
parent 2e1dc79a03
commit 744ec281d2
5 changed files with 101 additions and 8 deletions

View File

@@ -30,8 +30,13 @@ var (
const (
OPEN_TRACING_PARAMS_MARKER = "@openTracingParams"
APP_ERROR_TYPE = "*model.AppError"
ERROR_TYPE = "error"
)
func isError(typeName string) bool {
return strings.Contains(typeName, APP_ERROR_TYPE) || strings.Contains(typeName, ERROR_TYPE)
}
func init() {
flag.StringVar(&inputFile, "in", path.Join("..", "app_iface.go"), "App interface file")
flag.StringVar(&outputFile, "out", path.Join("..", "opentracing_layer.go"), "Output file")
@@ -199,7 +204,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorToBoolean": func(results []string) string {
for i, typeName := range results {
if strings.Contains(typeName, APP_ERROR_TYPE) {
if isError(typeName) {
return fmt.Sprintf("resultVar%d == nil", i)
}
}
@@ -207,7 +212,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorPresent": func(results []string) bool {
for _, typeName := range results {
if strings.Contains(typeName, APP_ERROR_TYPE) {
if isError(typeName) {
return true
}
}
@@ -215,7 +220,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorVar": func(results []string) string {
for i, typeName := range results {
if strings.Contains(typeName, APP_ERROR_TYPE) {
if isError(typeName) {
return fmt.Sprintf("resultVar%d", i)
}
}

View File

@@ -1634,6 +1634,11 @@ func (a *OpenTracingAppLayer) CreateDefaultMemberships(since int64) error {
defer span.Finish()
resultVar0 := a.app.CreateDefaultMemberships(since)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -2578,6 +2583,11 @@ func (a *OpenTracingAppLayer) DeleteGroupConstrainedMemberships() error {
defer span.Finish()
resultVar0 := a.app.DeleteGroupConstrainedMemberships()
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -3105,6 +3115,11 @@ func (a *OpenTracingAppLayer) DoPermissionsMigrations() error {
defer span.Finish()
resultVar0 := a.app.DoPermissionsMigrations()
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -3232,6 +3247,11 @@ func (a *OpenTracingAppLayer) DownloadFromURL(downloadURL string) ([]byte, error
defer span.Finish()
resultVar0, resultVar1 := a.app.DownloadFromURL(downloadURL)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
@@ -3334,6 +3354,11 @@ func (a *OpenTracingAppLayer) ExportPermissions(w io.Writer) error {
defer span.Finish()
resultVar0 := a.app.ExportPermissions(w)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -3522,6 +3547,11 @@ func (a *OpenTracingAppLayer) FilterNonGroupChannelMembers(userIds []string, cha
defer span.Finish()
resultVar0, resultVar1 := a.app.FilterNonGroupChannelMembers(userIds, channel)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
@@ -3539,6 +3569,11 @@ func (a *OpenTracingAppLayer) FilterNonGroupTeamMembers(userIds []string, team *
defer span.Finish()
resultVar0, resultVar1 := a.app.FilterNonGroupTeamMembers(userIds, team)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
@@ -4785,6 +4820,11 @@ func (a *OpenTracingAppLayer) GetConfigFile(name string) ([]byte, error) {
defer span.Finish()
resultVar0, resultVar1 := a.app.GetConfigFile(name)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
@@ -9079,6 +9119,11 @@ func (a *OpenTracingAppLayer) ImportPermissions(jsonl io.Reader) error {
defer span.Finish()
resultVar0 := a.app.ImportPermissions(jsonl)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -10928,6 +10973,11 @@ func (a *OpenTracingAppLayer) RegisterPluginCommand(pluginId string, command *mo
defer span.Finish()
resultVar0 := a.app.RegisterPluginCommand(pluginId, command)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -10945,6 +10995,11 @@ func (a *OpenTracingAppLayer) ReloadConfig() error {
defer span.Finish()
resultVar0 := a.app.ReloadConfig()
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -12222,6 +12277,11 @@ func (a *OpenTracingAppLayer) SendAckToPushProxy(ack *model.PushNotificationAck)
defer span.Finish()
resultVar0 := a.app.SendAckToPushProxy(ack)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -12389,6 +12449,11 @@ func (a *OpenTracingAppLayer) SendNotifications(post *model.Post, team *model.Te
defer span.Finish()
resultVar0, resultVar1 := a.app.SendNotifications(post, team, channel, sender, parentPostList)
if resultVar1 != nil {
span.LogFields(spanlog.Error(resultVar1))
ext.Error.Set(span, true)
}
return resultVar0, resultVar1
}
@@ -12860,6 +12925,11 @@ func (a *OpenTracingAppLayer) SetPhase2PermissionsMigrationStatus(isComplete boo
defer span.Finish()
resultVar0 := a.app.SetPhase2PermissionsMigrationStatus(isComplete)
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}
@@ -13217,6 +13287,11 @@ func (a *OpenTracingAppLayer) SetupInviteEmailRateLimiting() error {
defer span.Finish()
resultVar0 := a.app.SetupInviteEmailRateLimiting()
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}

View File

@@ -18,7 +18,15 @@ import (
"text/template"
)
const OPEN_TRACING_PARAMS_MARKER = "@openTracingParams"
const (
OPEN_TRACING_PARAMS_MARKER = "@openTracingParams"
APP_ERROR_TYPE = "*model.AppError"
ERROR_TYPE = "error"
)
func isError(typeName string) bool {
return strings.Contains(typeName, APP_ERROR_TYPE) || strings.Contains(typeName, ERROR_TYPE)
}
func main() {
if err := buildTimerLayer(); err != nil {
@@ -212,7 +220,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorToBoolean": func(results []string) string {
for i, typeName := range results {
if typeName == "*model.AppError" {
if isError(typeName) {
return fmt.Sprintf("resultVar%d == nil", i)
}
}
@@ -220,7 +228,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorPresent": func(results []string) bool {
for _, typeName := range results {
if typeName == "*model.AppError" {
if isError(typeName) {
return true
}
}
@@ -228,7 +236,7 @@ func generateLayer(name, templateFile string) ([]byte, error) {
},
"errorVar": func(results []string) string {
for i, typeName := range results {
if typeName == "*model.AppError" {
if isError(typeName) {
return fmt.Sprintf("resultVar%d", i)
}
}

View File

@@ -1495,6 +1495,11 @@ func (s *OpenTracingLayerChannelStore) MigratePublicChannels() error {
defer span.Finish()
resultVar0 := s.ChannelStore.MigratePublicChannels()
if resultVar0 != nil {
span.LogFields(spanlog.Error(resultVar0))
ext.Error.Set(span, true)
}
return resultVar0
}

View File

@@ -1401,7 +1401,7 @@ func (s *TimerLayerChannelStore) MigratePublicChannels() error {
elapsed := float64(timemodule.Since(start)) / float64(timemodule.Second)
if s.Root.Metrics != nil {
success := "false"
if true {
if resultVar0 == nil {
success = "true"
}
s.Root.Metrics.ObserveStoreMethodDuration("ChannelStore.MigratePublicChannels", success, elapsed)