tremor-runtime
tremor-runtime copied to clipboard
String formatting with args not working in definitions
Problem
Take this example config that tries to take the args values and format a string from them in the connector config:
define flow snot
flow
define connector client from http_client
args
host,
port
with
config = {
"url": "http://#{args.host}:#{args.port}/path"
}
end;
end;
Currently this results in an error like:
| ^^^^^ The expression isn't constant and can't be evaluated at compile time
Steps
- Try to start tremor with the config above
- See the error happen
Possible Solution(s)
Currently we only run the constant folder on the with values. The const folder cannot (or does not) replace the args paths with literals, so the constant folder reports that error.
Should we somehow resolve the args first to make this work?
What would be the most elegant way to solve this?
Interestingly, rewriting the above with the snippet below works just fine:
define flow snot
flow
define connector client from http_client
args
url
with
config = {
"url": args.url
}
end;
end;
It's not nice (aka not a solution), but does this work:
define flow snot
flow
define connector client from http_client
args
host,
port
with
config = {
"url": "http://" + args.host + ":" +args.port +"/path"
}
end;
end;
Other then that I suspect we fail on string literal rewriting for const folding? We should definitely fix that
This works! Which hints at an issue inside the ConstFolder.
Damn you ConstFolder, you had one job, folding consts and you didn't do it :sob:!
This seems to be fixed