cue-lang / cue

The home of the CUE language! Validate and define text-based and dynamic configuration
https://cuelang.org
Apache License 2.0
5.14k stars 294 forks source link

cue/cmd: unhandled task dependency detection #1595

Open verdverm opened 2 years ago

verdverm commented 2 years ago

What version of CUE are you using (cue version)?

v0.4.3-beta.1

Does this issue reproduce with the latest release?

yes: v0.4.2

What did you do?

The cue cmd resp case fails to detect the dependency

cue cmd body ./repro_tool.cue
cue cmd resp ./repro_tool.cue
cue cmd into ./repro_tool.cue

-- repro_tool.cue --
import "encoding/json"

apicall: {
  in: string
  r: { $id: "tool/file.Read", filename: in, contents: string }
  j: json.Unmarshal(r.contents)
  c: { 
    $id: "tool/http.Do"
    tls: verify: true
    method: j.method
    url: "\(j.host)\(j.path)"
    response: body: string
  }

  body: c.response.body
  resp: c.response
}

command: body: {
  call: apicall & { in: "req.json" }
  final: { $id: "tool/cli.Print", text: call.body }
}

command: resp: {
  call: apicall & { in: "req.json" }
  final: { $id: "tool/cli.Print", text: call.resp.body }
}

command: into: {
  call: apicall & { in: "req.json" }
  final: { $id: "tool/cli.Print", text: call.c.response.body }
}

What did you expect to see?

$ cue cmd resp ./dep_infer_001_tool.cue 
{"args":{},"headers":{"x-forwarded-proto":"https","x-forwarded-port":"443","host":"postman-echo.com","x-amzn-trace-id":"Root=1-623be975-50e5ee4a044b3bc6385bee82","accept-encoding":"gzip","user-agent":"Go-http-client/2.0"},"url":"https://postman-echo.com/get"}

What did you see instead?

$ cue cmd resp ./dep_infer_001_tool.cue 
command.resp.final.text: invalid string argument: non-concrete value string:
    ./dep_infer_001_tool.cue:26:3
    ./dep_infer_001_tool.cue:12:21
    ./dep_infer_001_tool.cue:26:35

in v0.4.2

$ cue cmd resp ./dep_infer_001_tool.cue 
command.resp.final.text: invalid string argument: non-concrete value string:
    ./dep_infer_001_tool.cue:26:3
    ./dep_infer_001_tool.cue:26:35

the error message has improved and increased accuracy! (in the beta)

rogpeppe commented 2 years ago

Thanks for the report.

For the record, call.body works, as does call.c.response.body, but call.resp.body does not. The issue description doesn't seem quite right to me, as dependencies from encoding/json are clearly being recognized in some of the cases here.

Here's a more complete and slightly slimmed down reproducer:

exec cue cmd resp ./repro_tool.cue

-- repro_tool.cue --
import "encoding/json"

apicall: {
  in: string
  r: { $id: "tool/file.Read", filename: in, contents: string }
  j: json.Unmarshal(r.contents)
  c: {
    $id: "tool/http.Do"
    tls: verify: true
    method: j.method
    url: "https://\(j.host)\(j.path)"
    response: body: string
  }
  resp: c.response
}

command: resp: {
  call: apicall & { in: "req.json" }
  final: { $id: "tool/cli.Print", text: call.resp.body }
}
-- req.json --
{
    "method": "GET",
    "host": "example.com",
    "path": "/"
}