tremor-runtime icon indicating copy to clipboard operation
tremor-runtime copied to clipboard

String formatting with args not working in definitions

Open mfelsche opened this issue 3 years ago • 4 comments
trafficstars

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

  1. Try to start tremor with the config above
  2. 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?

mfelsche avatar Aug 12 '22 08:08 mfelsche

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;

mfelsche avatar Aug 12 '22 08:08 mfelsche

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

Licenser avatar Aug 12 '22 08:08 Licenser

This works! Which hints at an issue inside the ConstFolder.

mfelsche avatar Aug 12 '22 08:08 mfelsche

Damn you ConstFolder, you had one job, folding consts and you didn't do it :sob:!

Licenser avatar Aug 12 '22 08:08 Licenser

This seems to be fixed

Licenser avatar Oct 12 '22 09:10 Licenser