x1unix/go-playground

使用go interpreter时提示invalid memory address or nil pointer dereference

xmapst opened this issue · 4 comments

示例

package main

import (
	"fmt"
	"os"

	"github.com/xmapst/logx"
)

func main() {
	fmt.Println("Hello World")
	fmt.Println(os.Getwd())
	logx.Info("你好世界")
}

错误信息:

Error
Go WebAssembly worker panicked. Please report this issue!

panic: runtime error: invalid memory address or nil pointer dereference
Stacktrace:
goroutine 129 [running]:
runtime/debug.Stack()
	runtime/debug/stack.go:24 +0x6
github.com/x1unix/go-playground/internal/gorepl.(*Handler).runProgram.func1()
	github.com/x1unix/go-playground/internal/gorepl/handler_js.go:116 +0x4
panic({0xe7c00, 0xcb6ac0})
	runtime/panic.go:884 +0x29
github.com/traefik/yaegi/interp.nodeType2(0x1093b00, 0x183b0e0, 0x13a9e00, {0x1352360, 0x3, 0x4})
	github.com/traefik/yaegi@v0.15.1/interp/type.go:1075 +0x693
github.com/traefik/yaegi/interp.genType(0x1093b00, 0x183b0e0, {0x1034800, 0x19}, 0x13a8a00, {0x1389908, 0x1, 0x1}, {0x1352360, 0x3, ...})
	github.com/traefik/yaegi@v0.15.1/interp/type.go:1125 +0x13
github.com/traefik/yaegi/interp.nodeType2(0x1093b00, 0x183b0e0, 0x13a72c0, {0x1352360, 0x2, 0x4})
	github.com/traefik/yaegi@v0.15.1/interp/type.go:841 +0x572
github.com/traefik/yaegi/interp.nodeType2(0x1093b00, 0x183b0e0, 0x13a7180, {0x1393ff0, 0x1, 0x2})
	github.com/traefik/yaegi@v0.15.1/interp/type.go:425 +0x377
github.com/traefik/yaegi/interp.nodeType2(0x1093b00, 0x183b0e0, 0x13a6c80, {0x1942ed0, 0x0, 0x1})
	github.com/traefik/yaegi@v0.15.1/interp/type.go:1071 +0x68f
github.com/traefik/yaegi/interp.nodeType(...)
	github.com/traefik/yaegi@v0.15.1/interp/type.go:400
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x197dcc0)
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:320 +0xd2
github.com/traefik/yaegi/interp.(*node).Walk(0x197dcc0, 0x138c2b8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x3
github.com/traefik/yaegi/interp.(*node).Walk(0x197db80, 0x138c2b8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*node).Walk(0x197d540, 0x138c2b8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x1093b00, 0x197d540, {0x1034300, 0x1d}, {0x108ba71, 0x16}, {0x18c82e0, 0x6})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0xc
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0x1093b00, {0x10356a0, 0x1e}, {0x108ba71, 0x16}, 0x1)
	github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0xdb
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x18c1a40)
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x28f
github.com/traefik/yaegi/interp.(*node).Walk(0x18c1a40, 0x138d0b0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x3
github.com/traefik/yaegi/interp.(*node).Walk(0x18c1680, 0x138d0b0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*node).Walk(0x18c1400, 0x138d0b0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x1093b00, 0x18c1400, {0x10356a0, 0x1e}, {0x10343e1, 0x17}, {0x1290ab7, 0x7})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0xc
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0x1093b00, {0x108a210, 0x16}, {0x10343e1, 0x17}, 0x1)
	github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0xdb
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x12d0500)
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x28f
github.com/traefik/yaegi/interp.(*node).Walk(0x12d0500, 0x138dea8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x3
github.com/traefik/yaegi/interp.(*node).Walk(0x12d0140, 0x138dea8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*node).Walk(0x12afe00, 0x138dea8, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x1093b00, 0x12afe00, {0x108a210, 0x16}, {0x108a0a9, 0xf}, {0x18d78ad, 0x3})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0xc
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0x1093b00, {0x1034260, 0x1d}, {0x108a0a9, 0xf}, 0x1)
	github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0xdb
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x1086500)
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x28f
github.com/traefik/yaegi/interp.(*node).Walk(0x1086500, 0x138eca0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x3
github.com/traefik/yaegi/interp.(*node).Walk(0x10863c0, 0x138eca0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*node).Walk(0x187dcc0, 0x138eca0, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x1093b00, 0x187dcc0, {0x1034260, 0x1d}, {0x108b9b1, 0x16}, {0x18d6100, 0x4})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0xc
github.com/traefik/yaegi/interp.(*Interpreter).importSrc(0x1093b00, {0x18d6c28, 0x4}, {0x108b9b1, 0x16}, 0x1)
	github.com/traefik/yaegi@v0.15.1/interp/src.go:108 +0xdb
github.com/traefik/yaegi/interp.(*Interpreter).gta.func1(0x1209180)
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:273 +0x28f
github.com/traefik/yaegi/interp.(*node).Walk(0x1209180, 0x138fa98, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:287 +0x3
github.com/traefik/yaegi/interp.(*node).Walk(0x1208b40, 0x138fa98, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*node).Walk(0x12088c0, 0x138fa98, 0x0)
	github.com/traefik/yaegi@v0.15.1/interp/interp.go:291 +0xf
github.com/traefik/yaegi/interp.(*Interpreter).gta(0x1093b00, 0x12088c0, {0x18d6c28, 0x4}, {0x18d6c28, 0x4}, {0x18d6c28, 0x4})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:20 +0xc
github.com/traefik/yaegi/interp.(*Interpreter).gtaRetry(0x1093b00, {0x18fbca8, 0x1, 0x1}, {0x18d6c28, 0x4}, {0x18d6c28, 0x4})
	github.com/traefik/yaegi@v0.15.1/interp/gta.go:395 +0x11
github.com/traefik/yaegi/interp.(*Interpreter).CompileAST(0x1093b00, {0x383738, 0x108c480})
	github.com/traefik/yaegi@v0.15.1/interp/program.go:92 +0x11
github.com/traefik/yaegi/interp.(*Interpreter).compileSrc(0x1093b00, {0x13540b0, 0xb0}, {0x0, 0x0}, 0x1)
	github.com/traefik/yaegi@v0.15.1/interp/program.go:64 +0x13
github.com/traefik/yaegi/interp.(*Interpreter).Compile(...)
	github.com/traefik/yaegi@v0.15.1/interp/program.go:33
github.com/x1unix/go-playground/internal/gorepl.(*Runner).Evaluate(0x1114080, {0x386fe0, 0x129c5c0}, {0x19d7c30, 0xb0, 0xb0})
	github.com/x1unix/go-playground/internal/gorepl/runner.go:63 +0xf
github.com/x1unix/go-playground/internal/gorepl.(*Handler).runProgram(0x114e8a0, {0x386fe0, 0x129c5c0}, {0x19d7c30, 0xb0, 0xb0})
	github.com/x1unix/go-playground/internal/gorepl/handler_js.go:123 +0x8
created by github.com/x1unix/go-playground/internal/gorepl.(*Handler).HandleRunProgram
	github.com/x1unix/go-playground/internal/gorepl/handler_js.go:77 +0x3b

@xmapst 对不起,我不会说中文,所以我用英语继续。

Go interpreter mode uses yaegi library which has problems running zap package (which your package use under the hood).

I'll try to investigate the issue but can't give any promises right now.

As a temporary solution, I suggest using a server to run Go programs:
image

@xmapst 对不起,我不会说中文,所以我用英语继续。

Go interpreter mode uses yaegi library which has problems running zap package (which your package use under the hood).

I'll try to investigate the issue but can't give any promises right now.

As a temporary solution, I suggest using a server to run Go programs: image

谢谢回答. 据观察应该是yaegi的局限性导致的

@xmapst

Can you please create an issue in Yaegi repository? Seems like Zap library started to use generics which Yaegi doesn't support right now (and I don't know when it will be implemented).

@xmapst

Can you please create an issue in Yaegi repository? Seems like Zap library started to use generics which Yaegi doesn't support right now (and I don't know when it will be implemented).

ok