Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

ERROR: no anchor processing for JSON when using std.parseYaml from python #1162

Open
ghost opened this issue Aug 1, 2024 · 2 comments
Open

Comments

@ghost
Copy link

ghost commented Aug 1, 2024

When using the python bindings (jsonnet-0.20.0), an abort is hit when using std.parseYaml with a file containing anchors.

Steps to reproduce: using jsonnet import, simply std.parseYaml on any YAML containing anchors.

Minimal example:

(env) jsonnet-python-yaml]$ python3
Python 3.11.4 (main, Jul 13 2023, 11:22:49) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18.0.2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _jsonnet as jsonnet
>>> jsonnet.evaluate_snippet('test.yaml', """
...     std.parseYaml(|||
...         foo: &foo bar
...         bar: *foo
...     |||)
... """
... )
ERROR: no anchor processing for JSON
Aborted (core dumped)

I can confirm this same abort when using evaluate_file too

(env)  jsonnet-python-yaml]$ cat test.jsonnet
std.parseYaml(|||
  foo: &foo bar
  bar: *foo
|||)
(env) [benjamin.jackson@stol-core1 jsonnet-python-yaml]$ python3
Python 3.11.4 (main, Jul 13 2023, 11:22:49) [GCC 8.5.0 20210514 (Red Hat 8.5.0-18.0.2)] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import _jsonnet as jsonnet
>>> jsonnet.evaluate_file('test.jsonnet')
ERROR: no anchor processing for JSON
Aborted (core dumped)

Env:

(env) [ jsonnet-python-yaml]$ pip freeze
jsonnet==0.20.0
(env) [jsonnet-python-yaml]$ uname -a
Linux xx 5.4.17-2011.7.4.el8uek.x86_64 #2 SMP Fri Oct 2 14:39:04 PDT 2020 x86_64 x86_64 x86_64 GNU/Linux
(env) [jsonnet-python-yaml]$ cat /etc/redhat-release
Red Hat Enterprise Linux release 8.3 (Ootpa)
@ghost
Copy link
Author

ghost commented Aug 1, 2024

For the record, the jsonnet cli does not choke on these same inputs:

(env) [jsonnet-python-yaml]$ jsonnet test.jsonnet
{
   "bar": "bar",
   "foo": "bar"
}

@ghost
Copy link
Author

ghost commented Aug 1, 2024

Actually, this exact issue is present with pure libjsonnet:

#include <iostream>
extern "C" {
#include <libjsonnet.h>
}

int main(int argc, char** argv)
{
    JsonnetVm *vm = jsonnet_make();
    int error{};
    char *result = jsonnet_evaluate_snippet(vm, "test.jsonnet", R"(
        std.parseYaml(|||
            foo: &foo bar
            bar: *foo
        |||)
    )", &error);

    if (error)
    {
        std::cerr << "Error: " << result << std::endl;
    }
    else
    {
        std::cout << result << std::endl;
    }
    jsonnet_realloc(vm, result, 0);
    jsonnet_destroy(vm);
}
(env) [jsonnet-go-c]$ LD_LIBRARY_PATH=/home/benjamin.jackson/repos/github/google/jsonnet/build ./a.out 
/home/benjamin.jackson/repos/github/google/jsonnet/third_party/rapidyaml/ryml_all.hpp:23120:JSON does not have anchors
Aborted (core dumped)

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
0 participants