Skip to content

πŸ–οΈ Quickstart issues with Go (dagger init + dagger call)Β #7941

Closed

Description

@solita-petterizit

What happened? What did you expect to happen?

Hey! I'm testing out Dagger for the first time and followed the quickstart guide.

When I ran dagger init --sdk=go in the root of my existing repository (not hello-dagger), it generated a dagger Go module:

$ tree dagger
dagger
β”œβ”€β”€ .gitattributes
β”œβ”€β”€ .gitignore
β”œβ”€β”€ dagger.gen.go
β”œβ”€β”€ go.mod
β”œβ”€β”€ go.sum
β”œβ”€β”€ internal
β”‚Β Β  β”œβ”€β”€ dagger
β”‚Β Β  β”‚Β Β  └── dagger.gen.go
β”‚Β Β  β”œβ”€β”€ querybuilder
β”‚Β Β  β”‚Β Β  β”œβ”€β”€ marshal.go
β”‚Β Β  β”‚Β Β  └── querybuilder.go
β”‚Β Β  └── telemetry
β”‚Β Β      β”œβ”€β”€ attrs.go
β”‚Β Β      β”œβ”€β”€ env.go
β”‚Β Β      β”œβ”€β”€ exporters.go
β”‚Β Β      β”œβ”€β”€ init.go
β”‚Β Β      β”œβ”€β”€ live.go
β”‚Β Β      β”œβ”€β”€ logging.go
β”‚Β Β      β”œβ”€β”€ proxy.go
β”‚Β Β      β”œβ”€β”€ span.go
β”‚Β Β      └── transform.go
└── main.go

4 directories, 18 files

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"
)

type RepoName struct{}

func (m *RepoName) Echo(stringArg string) string {
        return stringArg
}

// Other example targets

Dagger info:

$ dagger version
dagger v0.12.0 (registry.dagger.io/engine) linux/amd64

$ cat dagger.json
{
  "name": "repo-name",
  "sdk": "go",
  "source": "dagger",
  "engineVersion": "v0.12.0"
}

Running on WSL2 Ubuntu 22.04 with Docker Desktop.

Activity

  1. solita-petterizit commented on Jul 17, 2024

    @solita-petterizit
    Author

    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

    Using dagger query with 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:

    Stderr:
    # dagger/repo-name
    ./main.go:43:6: main redeclared in this block
            ./dagger.gen.go:55:6: other declaration of main

    When looking at the dagger call output with a bunch of verbosity, there's this line where the main() is actually declared:

            βœ” bf1f9897210e8500 Directory@xxh3:607b62fe5dc8b7ab.withoutFile(path: "dagger/dagger.gen.go"): Directory! = xxh3:ac6ecf8a3382952b 0.0s

    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:

            βœ” 46e334a7ea4c6338 Directory@xxh3:c40aa1495fddc0e9.withoutFile(path: "dagger/dagger.gen.go"): Directory! = xxh3:6a6a1d5a0e0bccff 0.0s
              βœ” 169ae8c7234fa44e rm /dagger/dagger.gen.go 0.0s
            βœ” c8d7dbfa43826249 Container@xxh3:20232105a1c51f3c.withMountedFile(
                path: "/schema.json"
                source: βœ” b2d7fe791160c70f Directory.file(path: "schema.json"): File! = xxh3:754c3dedfb6abfb2 0.0s
              ): Container! = xxh3:e608631d96c87a60 0.0s
            βœ” 70baf6d773e04fc5 Container@xxh3:36ccb247391e997c.withMountedDirectory(
                path: "/src"
                source: βœ” 46e334a7ea4c6338 Directory@xxh3:c40aa1495fddc0e9.withoutFile(path: "dagger/dagger.gen.go"): Directory! = xxh3:6a6a1d5a0e0bccff 0.0s
              ): Container! = xxh3:bc5715ae35fc43f4 0.0s
            βœ” a1eac769338fd380 Container@xxh3:e608631d96c87a60.withWorkdir(path: "/src/dagger"): Container! = xxh3:8333131c961bbd3a 0.0s
            βœ” a582acc4e951cb3c Container@xxh3:bc5715ae35fc43f4.withoutDefaultArgs: Container! = xxh3:aa4139d7e7133bc0 0.0s
            βœ” 3eabdfea43acb719 Container@xxh3:8333131c961bbd3a.withExec(args: ["codegen", "--output", "/src", "--module-context-path", "/src/dagger", "--module-name", "repo-name", "--introspection-json-path", "/schema.json"], experimentalPrivilegedNesting: true): Container! = xxh3:f9724bce2e6a3ac5 0.8s
              βœ” f29c05977f397c81 load cache: creating dagger metadata 0.0s
              βœ” 62076e95f59abddd exec codegen --output /src --module-context-path /src/dagger --module-name repo-name --introspection-json-path /schema.json 0.7s
              ┃ generating go module: repo-name
              ┃ writing dagger/dagger.gen.go # <--- Here
              ┃ writing dagger/go.mod
              ┃ writing dagger/go.sum
              ┃ running post-command: go mod tidy
              ┃ needs another pass...
              ┃ writing dagger/dagger.gen.go
              ┃ writing dagger/go.mod
              ┃ writing dagger/go.sum
              ┃ running post-command: go mod tidy
              ┃ done!
  2. jedevc commented on Jul 17, 2024

    @jedevc
    Contributor

    Heya πŸ‘‹

    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.

  3. solita-petterizit commented on Jul 17, 2024

    @solita-petterizit
    Author

    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:

    1. mkdir new-project && cd new-project
    2. dagger init --sdk=go
    3. 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.

    Baffling πŸ˜„

  4. jedevc commented on Jul 17, 2024

    @jedevc
    Contributor

    Yeah, those steps look right to me.

    Could it have something to do with the repo structure that dagger init was ran in?

    That's potentially possible for sure. You wouldn't happen to have a go.work at the top-level?

  5. solita-petterizit commented on Jul 18, 2024

    @solita-petterizit
    Author

    No go.work at 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:

    1. mkdir a-project && cd a-project
    2. dagger init --sdk=go
    3. dagger call echo --stringArg pingpong

    Then try this repro, which should repeat the failure:

    1. mkdir a-b-c-d-e-f-project && cd a-b-c-d-e-f-project
    2. dagger init --sdk=go
    3. dagger call echo --stringArg pingpong

    Edit: Actually, it seems to happen if any part in the path is a single character. I.e. this-is-a-project (a).

  6. rajatjindal commented on Jul 23, 2024

    @rajatjindal
    Contributor

    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)

    golang playground link to show the issue: https://go.dev/play/p/sSztAY-7AMD

  7. rajatjindal commented on Jul 24, 2024

    @rajatjindal
    Contributor

    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....

  8. helderco commented on Jul 24, 2024

    @helderco
    Contributor

    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.

  9. rajatjindal commented on Jul 25, 2024

    @rajatjindal
    Contributor

    This is indeed happening due to how strcase.ToCamel works for string like AModule, where it is returning Amodule.

    This causes the logic in namespaceObject function to fail and that returns AModuleAmodule, 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.

  10. sipsma commented on Jul 26, 2024

    @sipsma
    Contributor

    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.

  11. jpadams commented on Jul 31, 2025

    @jpadams
    Contributor

    @jedevc This is still a problem with v0.18

    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.

  12. locked and limited conversation to collaborators on Mar 24, 2026
  13. converted this issue into a discussion #12265 on Mar 24, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions