#dagger.Platform optionals

1 messages ยท Page 1 of 1 (latest)

cloud void
#

hm, i can't seem to repro on v0.12.6 ๐Ÿ˜ข
i've got the following module:

package main

import (
    "dagger/foo/internal/dagger"
)

type Foo struct{}

// Returns a container that echoes whatever string argument is provided
func (m *Foo) Thing(
    // +optional
    platform dagger.Platform,
) string {
    return "hello"
}

calling this works as expected:

dagger call thing
Full trace at https://dagger.cloud/jedevc/traces/903f0d8b93404c95eea6c7247ee3fc7e

โœ” connect 0.8s
โœ” initialize 5.1s
โœ” prepare 0.0s
โœ” foo: Foo! 0.0s
โœ” Foo.thing: String! 0.9s

hello
#

do you have a reproducer? i can't seem to get it to happen, sorry ๐Ÿ˜ข

#

dagger.Platform optionals

elder dust
#

Here is the code causing the problem:

// Build clientcompat binary.
func (m *Twirp) Build(
    // Target platform in "[os]/[platform]/[version]" format (e.g., "darwin/arm64/v7", "windows/amd64", "linux/arm64").
    //
    // +optional
    platform dagger.Platform,
) *dagger.File {
    return m.build(platform, "dev")
}

func (m *Twirp) build(platform dagger.Platform, version string) *dagger.File {
    if version == "" {
        version = "unknown"
    }

    return dag.Go(dagger.GoOpts{
        Version: goVersion,
    }).
        WithSource(m.Source).
        WithPlatform(platform).
        Build(dagger.GoWithSourceBuildOpts{
            Pkg:      "./protoc-gen-twirp_php",
            Trimpath: true,
            Ldflags: []string{
                "-s", "-w",
                "-X", "main.version=" + version,
            },
        })
}
#
marshal: json: error calling MarshalJSON for type *dagger.File: input: go.withSource.withPlatform resolve: failed to set call inputs: failed to convert arg "platform": "" is an invalid OS component of "": O
SAndVersion specifier component must match "^([A-Za-z0-9_-]+)(?:\\(([A-Za-z0-9_.-]*)\\))?$": invalid argument
#

So the problem occurs when it's passed to another module.

cloud void
#

oh i see

#

hm that's definitely "intentional", but yeah, weird

elder dust
#

I need to check if it's coming from the module itself

#

But I think the error comes from Dagger

elder dust
cloud void
#

hm, fair

#

i can take a look this week

elder dust
#

So an empty platform is handled

cloud void
#

sorry, for slow responses on everything, i'm completely swamped here sorry

#

๐Ÿ™

#

hm, ah that's entirely expected actually - that module needs to have an // +optional

#

i'm not sure why that used to work though

elder dust
#

Oh, good point

#

Not sure if it should be optional or the caller should handle that

cloud void
#

i admit it's super weird to be able to have an invalid platform object, i wonder if it would make sense to prefer this as a *, then it can be nil? but then, i guess you can't pass it to WithPlatform

elder dust
#

I guess there is no harm in making it optional in the Go module