google / google/go-jsonnet

Detect infinite import cycles

Open
#353 4 comments 0 reactions 0 assignees View on GitHub
enhancement
Dominant language
Go
Stars
1.8k
Forks
263
PR merge metrics
No merged PRs in 30d

Description

Right now, `jsonnet` fails instead of detecting an import cycle:

```jsonnet
# main.jsonnet
(import ",/main.jsonnet")
+ { /* ... */ }
```

results in

```
evaluating: RUNTIME ERROR: max stack frames exceeded.
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
...
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
main.jsonnet:1:2-25 $
During evaluation
```

Cases that should be detected:

- self-importing (above example)
- mutual importing (`a` importing `b` importing `a`)
- maybe infinite circles (a -> b -> c -> a) ie. record where we already were and fail if we import a file in the chain again

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.