force
force copied to clipboard
Using the same struct name in two different functions causes an unexpected error
This code:
func(){
TestFunctionTwo := func(f struct{AnotherStringParameter string}) {
Infof(Sprintf("TestFunctionTwo AnotherStringParameter: %s", f.AnotherStringParameter))
}
TestFunctionOne := func(f struct{StringParameter string}) {
Infof(Sprintf("TestFunctionOne StringParameter: %s", f.StringParameter))
TestFunctionTwo(_{AnotherStringParameter: f.StringParameter})
}
TestFunctionOne(_{StringParameter: "test"})
}
Causes this error:
$ force -d test.force
DEBU Found setup file setup.force. force/main.go:149
DEBU Add event source Oneshot(). runner/parser.go:177
DEBU Started process Process antaeus-1. runner/run.go:304
DEBU Fan in events: Oneshot() runner/run.go:187
DEBU Fan in received event Oneshot(time=2019-11-06 20:53:39.949039971 +0000 UTC). runner/run.go:202
DEBU Runner(pid=8990) waiting for Process antaeus-1 runner/run.go:151
DEBU [ANTAEUS-1] Process antaeus-1 has received Oneshot(time=2019-11-06 20:53:39.949039971 +0000 UTC). proc:antaeus-1 runner/local.go:141
INFO Process antaeus-1 triggered by Oneshot(time=2019-11-06 20:53:39.949039971 +0000 UTC) runner/run.go:272
INFO [ANTAEUS-1] TestFunctionOne StringParameter: test id:d5b4dd7e proc:antaeus-1 log/log.go:275
ERRO [ANTAEUS-1] Process antaeus-1 failed after running for 219.313µs. error:[
ERROR REPORT:
Original Error: *trace.BadParameterError f does not have a field StringParameter in struct { AnotherStringParameter force.StringVar }{AnotherStringParameter:force.StringVar{Expression:(*force.VarRef)(0xc000822880)}}
Stack Trace:
/home/gus/go/src/github.com/gravitational/force/vars.go:54 github.com/gravitational/force.GetField
/home/gus/go/src/github.com/gravitational/force/vars.go:81 github.com/gravitational/force.(*VarRef).Eval
/home/gus/go/src/github.com/gravitational/force/force.go:315 github.com/gravitational/force.StringVar.Eval
/home/gus/go/src/github.com/gravitational/force/vars.go:90 github.com/gravitational/force.(*VarRef).Eval
/home/gus/go/src/github.com/gravitational/force/eval.go:252 github.com/gravitational/force.Eval
/home/gus/go/src/github.com/gravitational/force/eval.go:244 github.com/gravitational/force.Eval
/home/gus/go/src/github.com/gravitational/force/gen.go:238 github.com/gravitational/force.(*ConvertedFunc).Eval
/home/gus/go/src/github.com/gravitational/force/shell.go:18 github.com/gravitational/force.EvalString
/home/gus/go/src/github.com/gravitational/force/pkg/log/log.go:263 github.com/gravitational/force/pkg/log.(*InfofAction).Eval
/home/gus/go/src/github.com/gravitational/force/shell.go:521 github.com/gravitational/force.(*SequenceAction).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:202 github.com/gravitational/force.(*LambdaFunctionCall).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:231 github.com/gravitational/force.(*LambdaFunctionCall).Eval
/home/gus/go/src/github.com/gravitational/force/shell.go:521 github.com/gravitational/force.(*SequenceAction).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:202 github.com/gravitational/force.(*LambdaFunctionCall).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:231 github.com/gravitational/force.(*LambdaFunctionCall).Eval
/home/gus/go/src/github.com/gravitational/force/shell.go:521 github.com/gravitational/force.(*SequenceAction).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:202 github.com/gravitational/force.(*LambdaFunctionCall).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/lambda.go:231 github.com/gravitational/force.(*LambdaFunctionCall).Eval
/home/gus/go/src/github.com/gravitational/force/shell.go:521 github.com/gravitational/force.(*SequenceAction).EvalWithScope
/home/gus/go/src/github.com/gravitational/force/shell.go:541 github.com/gravitational/force.(*SequenceAction).Eval
/home/gus/go/src/github.com/gravitational/force/pkg/runner/local.go:171 github.com/gravitational/force/pkg/runner.(*LocalProcess).triggerActions.func1
/usr/local/go/src/runtime/asm_amd64.s:1357 runtime.goexit
User Message: f does not have a field StringParameter in struct { AnotherStringParameter force.StringVar }{AnotherStringParameter:force.StringVar{Expression:(*force.VarRef)(0xc000822880)}}
] id:d5b4dd7e proc:antaeus-1 runner/local.go:174
DEBU Runner got an exit event, gracefully shutting down. runner/run.go:251
INFO Process antaeus-1 triggered by Exit(code=-1) runner/run.go:272
DEBU [ANTAEUS-1] Process antaeus-1 has received Exit(code=-1). proc:antaeus-1 runner/local.go:141
DEBU [ANTAEUS-1] Has received an exit event, exiting. proc:antaeus-1 runner/local.go:143
DEBU [ANTAEUS-1] Process antaeus-1 has triggered an exit event, exiting. proc:antaeus-1 runner/local.go:144
DEBU Process antaeus-1 has exited. runner/run.go:156
DEBU Process group is shutting down, running process count: 0 runner/run.go:236
DEBU Process group shut down successfully. runner/run.go:238
DEBU Process group has shut down with event: Exit(code=-1). force/main.go:72
This can be mitigated by renaming the f struct in one of the functions to something else.