#Dagger code generation fails when using optional value in interface

1 messages · Page 1 of 1 (latest)

remote ivy
#

Defining an interface which accepts an optional value causes the code generation to fail with this error:

Error: generate code: error formatting generated code: 61:1: expected declaration, found '%' (and 10 more errors)

Line 61 of the generated code:

%!v(PANIC=GoString method: Error 119:42: missing ',' in parameter list while formatting source:

The source is formatted using gofmt

Additional context: the issue only arises, if another function in the same interface requires a context argument.

To reproduce: repo containing the extended example code from the interfaces documentation:
https://github.com/puzzle/dagger-interface-example

GitHub

Contribute to puzzle/dagger-interface-example development by creating an account on GitHub.

remote ivy
#

Update: minimal setup to reproduce the issue:

type Fooer interface {
    DaggerObject
    Foo(ctx context.Context, bar int) (string, error)
    HasBar(ctx context.Context) (bool, error)
    Lint(dir *dagger.Directory, pass bool) *dagger.Directory
}

No optional argument involved here.
If HasBar or Lint is omitted, the code generation issue disappears.

gray crater
#

Checking this out! One interesting failure I see in codegen is

%!v(PANIC=GoString method: Error 21:16: expected ';', found 'type' (and 4 more errors) while formatting source:
  func (r MyModule) MarshalJSON () ([]byte,error) {
var concrete struct{}
return json . Marshal (& concrete)
}

 func (r * MyModule) UnmarshalJSON (bs []byte) (error) {
var concrete struct{}
err := json . Unmarshal (bs,& concrete)
if err != nil {
return err
}
return nil
}

comparing this to a successfully codegened module, it should look like

func (r *Binding) MarshalJSON() ([]byte, error) {
    id, err := r.ID(marshalCtx)
    if err != nil {
        return nil, err
    }
    return json.Marshal(id)
}
func (r *Binding) UnmarshalJSON(bs []byte) error {
    var id string
    err := json.Unmarshal(bs, &id)
    if err != nil {
        return err
    }
    *r = *dag.LoadBindingFromID(BindingID(id))
    return nil
}
#

ok I got it to codegen 😅 I'm not sure why the errors presented like that, but i'm opening a PR with the fix

#

Looks like this is wrong in the docs, updating that now

#

Actually that's not it 🤔 Maybe it was just the imports