yaegi: import "go.uber.org/zap" fails

The following program sample.go triggers an unexpected result

package main

import (
	"time"

	"go.uber.org/zap"
)

func main() {
	logger, _ := zap.NewProduction()
	// defer logger.Sync() // flushes buffer, if any
	sugar := logger.Sugar()
	sugar.Infow("failed to fetch URL",
		// Structured context as loosely typed key-value pairs.
		"url", "blabla",
		"attempt", 3,
		"backoff", time.Second,
	)
	sugar.Infof("Failed to fetch URL: %s", "blabla")
}

Expected result

{"level":"info","ts":1625585709.656375,"caller":"yaegi/foo.go:15","msg":"failed to fetch URL","url":"blabla","attempt":3,"backoff":1}
{"level":"info","ts":1625585709.656471,"caller":"yaegi/foo.go:21","msg":"Failed to fetch URL: blabla"}

Got

% yaegi run -unrestricted -unsafe ./sample.go
run: ./foo.go:8:2: import "go.uber.org/zap" error: /Users/mpl/src/go.uber.org/zap/array.go:26:2: import "go.uber.org/zap/zapcore" error: /Users/mpl/src/go.uber.org/zap/zapcore/entry.go:31:2: import "go.uber.org/zap/internal/exit" error: /Users/mpl/src/go.uber.org/zap/internal/exit/exit.go:32:2: not enough arguments in call to real

Yaegi Version

devel

Additional Notes

Hints at: https://github.com/uber-go/zap/blob/master/internal/exit/exit.go#L27

About this issue

  • Original URL
  • State: closed
  • Created 3 years ago
  • Comments: 17 (3 by maintainers)

Commits related to this issue

Most upvoted comments

Thank you, and many thanks to @mvertes for his incredible work 🚀

The plugin’s system inside Traefik is based on Yaegi, then there is no other way. You have to wait for the Yaegi fix or fork go.uber.org/zap to fix the problem with the real function.