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

panic: field lacking {function | object | value} doesn't contain the field that causes the error #61

Open
Makeshift opened this issue Nov 23, 2024 · 0 comments

Comments

@Makeshift
Copy link

I'm currently trying to understand how to implement docsonnet into a library I'm building, but am having a lot of trouble troubleshooting it as pretty much every failure results in a very opaque error:

 ± docsonnet lib/main.libsonnet
Extracting from Jsonnet
Transforming to docsonnet model
panic: field  lacking {function | object | value}

goroutine 1 [running]:
github.com/jsonnet-libs/docsonnet/pkg/docsonnet.loadField({0xa8bf58, 0x0}, 0xc000502e70, 0xc000502e40)
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/pkg/docsonnet/fast.go:93 +0x17d
github.com/jsonnet-libs/docsonnet/pkg/docsonnet.loadNested({0xc0004e6df0, 0xa}, 0xc000502e40)
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/pkg/docsonnet/fast.go:67 +0x1c6
github.com/jsonnet-libs/docsonnet/pkg/docsonnet.loadNested({0xc0004e6e80, 0x9}, 0xc000502e10)
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/pkg/docsonnet/fast.go:72 +0x267
github.com/jsonnet-libs/docsonnet/pkg/docsonnet.fastLoad(0xc000502db0)
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/pkg/docsonnet/fast.go:42 +0x3e7
github.com/jsonnet-libs/docsonnet/pkg/docsonnet.Transform({0xc000510a00, 0x4e7, 0x500})
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/pkg/docsonnet/load.go:70 +0xbe
main.main.func1(0xc0000f0600?, {0xc000030f10?, 0x1?, 0x1?})
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/main.go:43 +0x247
github.com/go-clix/cli.(*Command).execute(0xc0000cae60, {0xc000016050, 0x1, 0x1})
        /home/connor/go/pkg/mod/github.com/go-clix/[email protected]/command.go:120 +0x451
github.com/go-clix/cli.(*Command).Execute(0xc0000cae60)
        /home/connor/go/pkg/mod/github.com/go-clix/[email protected]/command.go:76 +0xbb
main.main()
        /home/connor/go/pkg/mod/github.com/jsonnet-libs/[email protected]/main.go:68 +0x385

This error doesn't tell me what actually caused the error. It's obviously receiving an empty field somewhere, but as someone new to doscsonnet, I haven't got a clue how or why. docsonnet --raw outputs something that looks pretty sane to me, but I'm not familiar enough with the tool yet to know valid from invalid.

In this case I have two files:

main.libsonnet:

local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';

{
  '#':: d.pkg(
    name='mypkg',
    url='',
    help='Opinionated templates'
  ),
  templates: {
    webservice: import 'templates/webservicetest.libsonnet'
  }
}

templates/webservicetest.libsonnet:

local d = import 'github.com/jsonnet-libs/docsonnet/doc-util/main.libsonnet';

{
  '#':: d.pkg(
    name='webservice',
    url='',
    help='foo'
  ),
  '#new':: d.fn(help=|||
    `new` returns a new instance of the webservice template
  |||, args=[
    d.arg('name', 'string', 'The name of the webservice'),
    d.arg('image', 'string', 'The Docker image to run in the webservice'),
  ]),
  new(name, image): {
    name: name,
    image: image
  }
}

With docsonnet --raw main.libsonnet I get:

{
   "#": {
      "help": "Opinionated templates",
      "import": "",
      "name": "mypkg"
   },
   "templates": {
      "webservice": {
         "#": {
            "help": "foo",
            "import": "",
            "name": "webservice"
         },
         "#new": {
            "function": {
               "args": [
                  {
                     "default": "The name of the webservice",
                     "name": "name",
                     "type": "string"
                  },
                  {
                     "default": "The Docker image to run in the webservice",
                     "name": "image",
                     "type": "string"
                  }
               ],
               "help": "`new` returns a new instance of the webservice template\n"
            }
         }
      }
   }
}

I'm assuming that to someone that knows what they're doing it must be pretty obvious what's wrong there, but a bit more detail in the error messages would be greatly appreciated.

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

No branches or pull requests

1 participant