Replies: 1 comment 2 replies
-
Original reply by @mpvl in cuelang/cue#927 (comment) Yes, absolutely. Although indeed it is good to design a language such that one does not need debugging support too much, it is still a critical feature. Issue #142 is already an old issue, but it is nonetheless considered high priority, and @myitcv is currently working on this, in fact. Linking evaluated code back to source is actually relatively easy, as CUE internally keeps track of all conjuncts, including line information, of which a result is composed. Position information is even kept across translations of foreign formats, like YAML (subject to the limits of the conversion libraries). The hardest part really in providing something like |
Beta Was this translation helpful? Give feedback.
-
Originally opened by @vikstrous2 in cuelang/cue#927
After having spent some time using CUE, I think back to when I was comparing CUE and cdk8s one of their major selling points was auto-completion and go to definition in the editor (normal programming language features). I thought that the simplicity of CUE would remove the need for this and the fact that it's not a traditional programming language would make these features obsolete, but I'm starting to feel like there's something important missing in CUE. This is essentially debuggability.
In a normal programming language, you can put in print statements. You can use go to definition. You can use auto-complete. You can use a debugger. In CUE, none of this is possible, so the only way to debug a CUE config issue is to diff the output or to delete code (let's just call CUE config "code" in the general sense) until you understand the remaining code.
I think access to more powerful debugging features is essential for wider adoption and for managing larger configs or having non-cue-experts contribute to configs. I'd like to see more ideas for debugging tools and strategies discussed, but I'll focus on one particular idea in this "discussion".
cue explain
commandI propose a
cue explain
command. Here's an example of how it would work:Input:
CUE eval output:
CUE explain usage:
CUE explain output:
The idea is to find all the lines of CUE config that affect the rendering of a particular output value. This example is very basic and I'm not particularly attached to the naming or output format, but it shows one potential starting point. The syntax for selecting elements to "explain" could be refined, the output format could be refined. This is just a starting point for a discussion.
Potential problems
Text editor integration would be incredibly useful for something like this, but to do that, we need to go from the "eval" output back to the source. Unfortunately, there's way too much freedom in the different ways that we can output configs from CUE, so going backwards is difficult in practice. In practice we never really use a raw
eval
and take its output directly. We usecmd
(_tool.cue files). The number of possible transformations that these files apply is not quite unlimited, but trying to go backwards from a file output is quite different from going backwards from an eval output. Let's say that we output configs with this tool.cue file:It would take quite a bit of reversing logic to figure out that
name
in the yaml filething.yaml
was produced by:I don't know if this is possible or not. I think it's possible if every standard library function keeps track of its source data, but I don't know enough about how CUE is implement to know if this is realistic to implement.
For completeness of the thought exercise, I'll show one way in which the above query would be run with the hypothetical cue explain command:
Beta Was this translation helpful? Give feedback.
All reactions