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
- interp: improve processing of recursive types Make sure to keep always a single copy of incomplete type structures. Remove remnants of recursive types processing. Now `import "go.uber.org/zap"` work... — committed to traefik/yaegi by mvertes 3 years ago
- interp: improve processing of recursive types Make sure to keep always a single copy of incomplete type structures. Remove remnants of recursive types processing. Now `import "go.uber.org/zap"` work... — committed to traefik/yaegi by mvertes 3 years ago
- interp: improve processing of recursive types Make sure to keep always a single copy of incomplete type structures. Remove remnants of recursive types processing. Now `import "go.uber.org/zap"` w... — committed to traefik/yaegi by mvertes 3 years ago
- interp: improve handling of methods defined on interfaces For methods defined on interfaces (vs concrete methods), the resolution of the method is necessarily delayed at the run time and can not be c... — committed to traefik/yaegi by mvertes a year ago
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 thereal
function.