#dagger.json issues
1 messages ยท Page 1 of 1 (latest)
@mortal fjord seeing this error:
Error: load package ".": package name is empty
Do these subdirectories exist? daggerverse/java, daggerverse/docker, daggerverse/oauth?
Error: failed to generate code: input: resolve: moduleSource: withName: withSDK: withSourceSubpath: resolveFromCaller: asModule: failed to create module: failed to update codegen and runtime: failed to generate code: failed to get modified source directory for go module sdk codegen: process "/usr/local/bin/codegen --module-context /src --module-name sonar --propagate-logs=true --introspection-json-path /schema.json" did not complete successfully: exit code: 1
Stderr:
Error: load package ".": package name is empty
Are you able to paste the output of find . or equivalent?
These do exist. They all work too when I dagger call them
can you run dagger functions from the root module?
This is find . from daggerverse dir
.
./docker
./docker/go.mod
./docker/querybuilder
./docker/querybuilder/marshal.go
./docker/querybuilder/querybuilder.go
./docker/dagger.gen.go
./docker/go.sum
./docker/.gitignore
./docker/dagger.json
./docker/.gitattributes
./docker/main.go
./oauth
./oauth/go.mod
./oauth/querybuilder
./oauth/querybuilder/marshal.go
./oauth/querybuilder/querybuilder.go
./oauth/dagger.gen.go
./oauth/go.sum
./oauth/.gitignore
./oauth/dagger.json
./oauth/.gitattributes
./oauth/main.go
./java
./java/go.mod
./java/querybuilder
./java/querybuilder/marshal.go
./java/querybuilder/querybuilder.go
./java/dagger.gen.go
./java/resources
./java/resources/settings.xml
./java/go.sum
./java/.gitignore
./java/dagger.json
./java/.gitattributes
./java/main.go
./sonar
./.gitattributes
That will tell us if the module is currently in a good state
OK, so at the moment there is no root module (no dagger.json at the root)
let me run that. I renamed that dagger.json to dagger.json.back just to see if removing it helps
ah I see
There is, I am unable to find . that one as that's a fairly big Go project
ok ๐
output of dagger functions from root (after setting back dagger.json)
Error: input: resolve: moduleSource: resolveFromCaller: asModule: initialize: module name and SDK must be set
What's the output of dagger version?
dagger v0.9.9 (registry.dagger.io/engine) darwin/arm64
are you able to share the contents of that dagger.json?
I did, let me repaste, I am redacting the name of the module but here it is
{
"name": "mymodule",
"dependencies": [
{
"name": "docker",
"source": "daggerverse/docker"
},
{
"name": "java",
"source": "daggerverse/java"
},
{
"name": "oauth",
"source": "daggerverse/oauth"
}
],
"engineVersion": "v0.9.9"
}
here's the contents of daggervers/docker/dagger.json
{
"name": "docker",
"sdk": "go",
"source": ".",
"engineVersion": "v0.9.9"
}
hmm, if I create a new folder in my home directory called daggertest/sonar and run dagger init --sdk=go --name=sonar it works.
thanks, and sorry for the repaste
total brainfart on my side
no worries!
So, it actually makes sense that dagger functions doesn't return anything useful, since your root module doesn't have any functions of its own. Obviously we need to add more polish, that error is too rough, but it's probably not what's blocking you.
@mortal fjord what are you trying to do where you are stuck?
right
For example this should work: dagger -m ./daggerverse/docker functions
And ideally, this should also work since you installed it as a dependency: dagger -m docker functions. Although @strong summit has been having issues getting that to work
So basically I am trying to build my own daggerverse. It was working fine pre-0.9.9. What I tried to do with the root is make it a module so I can call them via dagger -m docker ... etc.
Ah I see. Well to make your own daggerverse, you don't need a root dagger.json at all. As long as your individual modules load correctly, you shouldn't need to change anything.
I don't care too much about the root. I can live without it. But the biggest problem now is dagger engine has gotten into some bad state. i can't even initialize individual modules within my daggerverse folder
My own daggerverse repo hasn't changed in that regard in months. The only thing I need to fix at the moment, is how my individual modules handle optional arguments in Go. Other than that, no breaking change.
Ah, I see.
my individual modules had root specified. So when 0.9.9 came along I went into each module and did a dagger develop which restructured the dagger.json and removed root
Ok so far so good. Did you need that root to access shared files in the parent repo?
That was the idea yes. but based on recent changes to dagger I resorted to passing whatever needed via CLI args
I tried this in my daggerverse:
$ dagger version
dagger v0.9.9 (registry.dagger.io/engine) darwin/arm64
$ dagger init --sdk go ./sonar
WARNING: no LICENSE file found; generating one for you, feel free to change or remove license="Apache-2.0"
Initialized module sonar in ./sonar
$ cat dagger.json
cat: dagger.json: No such file or directory
$ cat sonar/dagger.json
{
"name": "sonar",
"sdk": "go",
"source": "dagger",
"engineVersion": "v0.9.9"
}
$
yes I see the same if I dagger init outside of this project..
(Don't love the default dagger/ in that context, but that's a separate design conversation with its own tradeoffs...)
yeah same
my default is .
cat daggerverse/java/dagger.json
{
"name": "java",
"sdk": "go",
"dependencies": [
{
"name": "docker",
"source": "../docker"
}
],
"source": ".",
"engineVersion": "v0.9.9"
}
Hello Nipuna, jumping in also. Did you manage to repro on the side apart your current daggerverse ?
From what I understand, you have a root module as such:
{
"name": "mymodule",
"dependencies": [
{
"name": "docker",
"source": "daggerverse/docker"
},
{
"name": "java",
"source": "daggerverse/java"
},
{
"name": "oauth",
"source": "daggerverse/oauth"
}
],
"engineVersion": "v0.9.9"
}
So a tree like this:
daggerverse
/docker
/java
/oauth
Now, each of these modules work with 0.9.9 when calling them from the root, and each of them have the engineVersion set as v0.9.9
dagger call -m ./docker
dagger call -m ./oauth
dagger call -m ./java
- Now, the docker have such
dagger.json:
{
"name": "docker",
"sdk": "go",
"source": ".",
"engineVersion": "v0.9.9"
}
- The java has:
{
"name": "java",
"sdk": "go",
"dependencies": [
{
"name": "docker",
"source": "../docker"
}
],
"source": ".",
"engineVersion": "v0.9.9"
}
``` and references the docker
What about the oauth, is it referencing any of these modules ?
To summarize, whenever you do a `dagger init newmodule`, in that configuration it breaks ?
Thanks for jumping in! And yes I think you summarized it pretty well. I haven't tried exactly to replicate yet outside of this structure yet. That's my next goal. I am going to copy the individual modules + code into a brand new folder and see what happens
the oauth module does not have deps. but there's another one in there that depends on another mod
so oauth is like this:
{
"name": "oauth",
"sdk": "go",
"source": ".",
"engineVersion": "v0.9.9"
}
yes exactly
Heres the other module with deps
{
"name": "(redacted)",
"sdk": "go",
"dependencies": [
{
"name": "docker",
"source": "../docker"
},
{
"name": "java",
"source": "../java"
}
],
"source": ".",
"engineVersion": "v0.9.9"
}
It all looks very vanilla. Hence why i'm stumped this is not working
hmm, so two modules are depended on docker, one with some depth. Ok, trying a repro from scratch on the side ๐
looks a lot like a state issue then. Did you try to kill the engine, remove its cache ?
by removing cache you mean remove the local volume? Is there anything else I need to clear?
it shall be enough โ
tried that, didn't make a difference ๐ฆ
I wonder if my existing project being a go project has something to do with it. That's the only difference between my repro attempt and original
Actually it's better like this, it shall be reproducable ๐ผ
interestingly dagger init --sdk=python --name=newmodule worked.. So something to do with Go.
and its not a conflict of the name of the module and the top level package name in go ?
dagger init --sdk=go --name=newmodule fails
I get the error regardless of the name of the module
what command did you use to make docker a deps to java ?
In the codebase, the issue is as such:
case 1:
if pkgs[0].Name == "" {
// this happens when loading an empty dir within an existing Go module
return nil, nil, fmt.Errorf("package name is empty")
}
return pkgs[0], fset, nil
I think dagger install. I stepped out for a bit will check when I get back. Really appreciate you looking into this!
so this is weird, this implies that the parent directory somewhere has a go.mod
but the find you've done doesn't show that
this looks specific to the Go SDK, as opposed to all the SDKs - what's weird to me is why this ever worked, this specific code path is quite old (like when we started zenith)
Sorry I am back to testing this. @verbal marlin I didn't get what you meant. My root dir is an existing Go project are you saying that's a conflict somehow?
yeah it looks like it - thankfully, i managed to reproduce this!
i'll open an issue
To reproduce this, try initializing a dagger module in a directory that already contains a go.mod. For example: $ git clone https://github.com/dagger/dagger.git $ dagger init --sdk=go โ ModuleSourc...
i left a suggested workaround, i'll try and come back and address this later - i'm a bit caught up today with an internal hackathon โค๏ธ
awesome! I can do the workaround for now as it only fails on new module creation. I won't have to do that many times.
Yes! That worked. Seems like folks developing CI modules for Go apps will run into this fairly often.
wow lol, it really is ridiculously easy to hit this everywhere isn't it ๐
can't believe it was such a pain to find it ๐
haha. I was the first unlucky soul to hit it I guess. Glad you figured it out though!
Thank you for tracking this down guys, and for your patience Nipuna
@mortal fjord I should have a fix for you in https://github.com/dagger/dagger/pull/6678
Should fix #6659 (cc @nipuna-perera).
This is a pretty common use case - we have a go.work at the root of a repo, and we want to create a dagger module for it with dagger init.
However, naively, th...
If you're comfortable testing against a dev engine, I'm curious if this resolves your issue
I think the issue is with parent go.works causing issues, but potentially there could be multiple things here
(also bleh, those couple of lines with the actual fix, if you average them out, i guess it's a nice average code-writing speed of 2 lines an hour ๐ข)
Woot!! I haven't done a lot of testing with the dev engine. I know at some point there was a engine module. Is there an updated document on how to test with the dev engine?
this is generally how I do it: https://docs.dagger.io/204441/contributing/#how-to-run-a-development-engine
easy enough, let me try that
bleh, didn't work. ./hack/dev failed because the internal Go image does not have my company CA certs. So it fails to go mod download ๐ฆ
I've been trying to use the workaround for this but I can't do much. When I rename the go.mod and go.work files, my autocompletion breaks. dagger develop seems to work but then it actually generates the code for the example module and not the one I have coded. When I name go.mod and go.work back, dagger develop fails with the same error I saw originally. So I am effectively stuck
hm, can you make sure that the go.work includes the go.mod defined by your dagger module
this is essentially what my fix does - makes sure it's included if you're using a go.work
yeah my go work has the new module. Let me double check
hmmm if your go.work has the dagger module included, and you're still getting the issue, then there's something else going on
go 1.21.3
toolchain go1.21.5
use (
.
./daggerverse/docker
./daggerverse/java
./daggerverse/lwc
./daggerverse/oauth
./daggerverse/sonar
)
./daggerverse/sonar is the module I am trying to build
and dagger develop in the sonar directory gives the package name is empty error?
hm, what's ls -lha ./daggerverse/sonar give?
I cropped where it shows my user
are there significant differences between that and the other dirs?
hmm.. other modules have a .gitignore but not the dagger folder. I thought i moved everything out of the dagger folder the other day
so that dagger folder also has a go.mod. I wonder if that's causing the issue
removing the dagger folder didn't change anything FWIW
oh, did you also update the source value in the dagger.json for that module
if you removed the dagger folder
oh I did not
let me update it
ok changing the source fixed it.
That error message could be better
yeah, i'm not actually sure how you got it though
So I guess the issue was, the dagger folder was not in go.work
it was the top level ./daggerverse/sonar folder that was in go.work