#dagger.Platform optionals
1 messages ยท Page 1 of 1 (latest)
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
we also have this usage in our own ci: https://github.com/dagger/dagger/blob/8a987be450e7920823b0b055553047625728d5ad/.dagger/cli.go#L18-L24
do you have a reproducer? i can't seem to get it to happen, sorry ๐ข
dagger.Platform optionals
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.
I need to check if it's coming from the module itself
I use this library to parse the platform: https://github.com/containerd/platforms
But I think the error comes from Dagger
It used to work though :/ (at least it does on 0.12.0)
BTW this is how the module is implemented: https://github.com/sagikazarmark/daggerverse/blob/main/go/main.go#L100
So an empty platform is handled
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
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
I guess there is no harm in making it optional in the Go module