You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
ποΈ Quickstart issues with Go (dagger init + dagger call)Β #7941
So, following the spirit of the quickstart, I tried to call the Echo example target with: dagger call echo --stringArg=ping (instead of replacing the contents immediately with quickstart-specific functions) and get the following output:
$ dagger call echo --stringArg=ping
β connect 3.6s
β initialize 0.5s
! main object not found
β resolving module ref 0.2s
β installing module 0.2s
β analyzing module 0.2s
! main object not found
Error: main object not found
Same output repeats with dagger call echo ping and dagger call echo.
What am I missing here? :)
My ./dagger/main.go looks like such:
package main
import (
"context""dagger/repo-name/internal/dagger"
)
typeRepoNamestruct{}
func (m*RepoName) Echo(stringArgstring) string {
returnstringArg
}
// Other example targets
I tried to start from scratch with version 0.11.9 and had the same exact issue, although a bit clearer logs:
$ dagger-0.11.9 call echo --stringArg=pong
β initialize 2.2s
! main object not found
β Module.initialize: Module! 0.9s
β exec go build -o /runtime . 0.8s # <-- This was not visible before
Is repo-name the literal value you're using here? I have a vague suspicion that that could have something to do with it. main object not found can potentially happen if the struct type you're using RepoName isn't the right one for repo-name. Not sure though, I can't seem to reproduce the exact issue you're having.
You shouldn't add a manual main definition - if you run dagger develop, you can see that dagger will generate one for you in dagger.gen.go.
It's something else, just redacted, but repository name follows those patterns. It was generated by dagger init to match the directory (repository) name I ran it in, generating repo-name/dagger.json, repo-name/LICENSE and repo-name/dagger/... structure.
Could it have something to do with the repo structure that dagger init was ran in? It has a Go application under repo-name/app and an assortment of other files in the root repo-name/..., things such as Makefiles, scripts, configuration etc. (but no go.mod or go.sum under that root).
Just to be clear, to get a simple dagger setup running with zero existing anything, the minimal steps would be:
mkdir new-project && cd new-project
dagger init --sdk=go
dagger call echo --stringArg pingpong
?
You shouldn't add a manual main definition - if you run dagger develop, you can see that dagger will generate one for you in dagger.gen.go.
That's what I was thinking as well. However, running dagger call fails as it is missing that main definition, since it does not load dagger.gen.go in the build environment, nor generate it, since it crashes before it gets to the generation part. When you add main manually, then it actually generates dagger.gen.go inside the build environment, and then crashes to redefinition.
This may be happening because of how strcase.ToCamel works (which is used here in dagger to identify if the name is the main object or not). and it seems like the behaviour has changed recently in that library as reported in iancoleman/strcase#39 (comment)
on trying this further, I am noticing that in schema on engine side, the module a-module, shows up as AModuleAmodule, while my-module, shows up as MyModule:
schema fetched using query:
{
__schema {
types {
name
}
}
}
I am still trying to connect dots as to why that might be....
This may be happening because of how strcase.ToCamel works (which is used here in dagger to identify if the name is the main object or not). and it seems like the behaviour has changed recently in that library as reported in iancoleman/strcase#39 (comment)
That library has issues. Even the names of the functions don't follow conventions:
ToCamel β should be ToPascal
ToLowerCamel β should be ToCamel
The acronym preservation is problematic, but it exists due to Go's naming conventions. However it brings ambiguity on where words should be separated. Codegen uses a different function in some places, with its own list of acronyms.
You may find that the naming conversion isn't being used consistently everywhere. If so, that needs to be fixed.
Sure there's more. If something else off the shelf handles this better that seems like the best route. But we should make sure whatever we go with we have some unit test coverage in our own code to check for libraries switching out implementations from under us.
mkdir a-mod && cd a-mod
dagger init --sdk go
# type AMod struct{}
a-mod β€ dagger call container-echo --string-arg foo
βΆ connect 0.2s
βΌ load module: . 0.3s ERROR
! main object not found, check that your module's name and main object match
βββ finding module configuration 0.1s
βββ initializing module 0.1s
βββ inspecting module metadata 0.0s
β°ββ loading type definitions 0.1s ERROR
! main object not found, check that your module's name and main object match
Full trace at https://dagger.cloud/dagger/traces/d60ac7b5b5a7acbfea4f9fe6174aec4b
vs
mkdir am-odd && cd am-odd
dagger init --sdk go
dagger call container-echo --string-arg foo
# works
related to #7373 that if the name of the module will be problematic we should bail out before module creation and give a good error message. Also need to document this.
Activity
solita-petterizit commentedon Jul 17, 2024
I tried to start from scratch with version 0.11.9 and had the same exact issue, although a bit clearer logs:
Using
dagger querywith examples from version 0.9 CLI docs do work fine.After manually adding the redeclaration of
func main() {}to the generated example under./dagger/main.go, I managed to get it to fail to just that:When looking at the
dagger calloutput with a bunch of verbosity, there's this line where themain()is actually declared:but for whatever reason, that file does not seem to be re-generated, like when it does in the redeclaration above, as visible from verbose logs:
jedevc commentedon Jul 17, 2024
Heya π
Is
repo-namethe literal value you're using here? I have a vague suspicion that that could have something to do with it.main object not foundcan potentially happen if the struct type you're usingRepoNameisn't the right one forrepo-name. Not sure though, I can't seem to reproduce the exact issue you're having.You shouldn't add a manual
maindefinition - if you rundagger develop, you can see that dagger will generate one for you indagger.gen.go.solita-petterizit commentedon Jul 17, 2024
It's something else, just redacted, but repository name follows those patterns. It was generated by
dagger initto match the directory (repository) name I ran it in, generatingrepo-name/dagger.json,repo-name/LICENSEandrepo-name/dagger/...structure.Could it have something to do with the repo structure that
dagger initwas ran in? It has a Go application underrepo-name/appand an assortment of other files in the rootrepo-name/..., things such as Makefiles, scripts, configuration etc. (but nogo.modorgo.sumunder that root).Just to be clear, to get a simple dagger setup running with zero existing anything, the minimal steps would be:
mkdir new-project && cd new-projectdagger init --sdk=godagger call echo --stringArg pingpong?
That's what I was thinking as well. However, running
dagger callfails as it is missing thatmaindefinition, since it does not loaddagger.gen.goin the build environment, nor generate it, since it crashes before it gets to the generation part. When you addmainmanually, then it actually generatesdagger.gen.goinside the build environment, and then crashes to redefinition.Baffling π
jedevc commentedon Jul 17, 2024
Yeah, those steps look right to me.
That's potentially possible for sure. You wouldn't happen to have a
go.workat the top-level?solita-petterizit commentedon Jul 18, 2024
No
go.workat root level, no. But, I figured out what's up. π΅οΈDagger fails at some point if the folder name is in the format
<single character>-<anything else>(which matches my case).Try this repro:
mkdir a-project && cd a-projectdagger init --sdk=godagger call echo --stringArg pingpongThen try this repro, which should repeat the failure:
mkdir a-b-c-d-e-f-project && cd a-b-c-d-e-f-projectdagger init --sdk=godagger call echo --stringArg pingpongEdit: Actually, it seems to happen if any part in the path is a single character. I.e.
this-is-a-project(a).rajatjindal commentedon Jul 23, 2024
This may be happening because of how
strcase.ToCamelworks (which is used here in dagger to identify if the name is the main object or not). and it seems like the behaviour has changed recently in that library as reported in iancoleman/strcase#39 (comment)golang playground link to show the issue: https://go.dev/play/p/sSztAY-7AMD
rajatjindal commentedon Jul 24, 2024
on trying this further, I am noticing that in schema on engine side, the module
a-module, shows up asAModuleAmodule, whilemy-module, shows up asMyModule:schema fetched using query:
I am still trying to connect dots as to why that might be....
helderco commentedon Jul 24, 2024
That library has issues. Even the names of the functions don't follow conventions:
ToCamelβ should beToPascalToLowerCamelβ should beToCamelThe acronym preservation is problematic, but it exists due to Go's naming conventions. However it brings ambiguity on where words should be separated. Codegen uses a different function in some places, with its own list of acronyms.
You may find that the naming conversion isn't being used consistently everywhere. If so, that needs to be fixed.
rajatjindal commentedon Jul 25, 2024
This is indeed happening due to how
strcase.ToCamelworks for string likeAModule, where it is returningAmodule.This causes the logic in
namespaceObjectfunction to fail and that returnsAModuleAmodule, which triggers the said failure.this is in addition to the same issue during code generation as reported in one of the previous comment
thanks @solita-petterizit for provide such a precise testcase for reproducing the issue.
Now onto trying to identify a fix for it.
sipsma commentedon Jul 26, 2024
There does appear to be quite a few other implementations of all this out there, some I found:
Sure there's more. If something else off the shelf handles this better that seems like the best route. But we should make sure whatever we go with we have some unit test coverage in our own code to check for libraries switching out implementations from under us.
jpadams commentedon Jul 31, 2025
@jedevc This is still a problem with v0.18
vs
related to #7373 that if the name of the module will be problematic we should bail out before module creation and give a good error message. Also need to document this.