d5 / tengo

A fast script language for Go

Home Page:https://tengolang.com

Geek Repo:Geek Repo

Github PK Tool:Github PK Tool

Missing user function name in some error messages

qzb opened this issue · comments

When user function defined in module returns ErrWrongNumArguments or ErrInvalidArgumentType, error message doesn't include name of the function.

Example

package main

import (
	"fmt"

	"github.com/d5/tengo/v2"
)

func main() {
	m := tengo.NewModuleMap()
	m.AddBuiltinModule("mod", map[string]tengo.Object{
		"test": &tengo.UserFunction{
			Value: func(...tengo.Object) (tengo.Object, error) {
				return nil, tengo.ErrInvalidArgumentType{}
			},
			Name: "test",
		},
	})

	s := tengo.NewScript([]byte(`import("mod").test()`))
	s.SetImports(m)

	_, err := s.Run()
	fmt.Println(err) // Prints:
	                 // Runtime Error: wrong number of arguments in call to 'user-function:'
	                 //        at (main):1:1
}