Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

up to 1.20 and Hold business error #345

Closed
hesining opened this issue Mar 8, 2023 · 7 comments
Closed

up to 1.20 and Hold business error #345

hesining opened this issue Mar 8, 2023 · 7 comments

Comments

@hesining
Copy link
Contributor

hesining commented Mar 8, 2023

I find that my own error information of method and function turned to string, and I can't use it conveniently. The go 1.20 has the new function 'errors.Join' and I think the expr code about recover can modify like this

func (vm *VM) Run(program *Program, env interface{}) (_ interface{}, err error) {
	defer func() {
		if r := recover(); r != nil {
			f := &file.Error{
				Location: program.Locations[vm.ip-1],
			}

			var ok bool
			if err, ok = r.(error); !ok {
				f.Message = fmt.Sprintf("%v", r)
				err = f.Bind(program.Source)
			} else {
				err = errors.Join(err, f.Bind(program.Source))
			}
		}
	}()
//...
}

How about up to 1.20 and use the new feature ?

@antonmedv
Copy link
Member

Currently some users of Expr still use go1.13. We have unit tests there too.

One way to get your own errors back: save errors in env struct’s field.

@hesining
Copy link
Contributor Author

hesining commented Mar 8, 2023

Currently some users of Expr still use go1.13. We have unit tests there too.

One way to get your own errors back: save errors in env struct’s field.

Yes, It's a way. save it in env struct’s field instead of return it. The only problem is that users should change their writing habits.

@GeraldXv
Copy link

GeraldXv commented Mar 8, 2023

I also encountered a similar problem.

@antonmedv
Copy link
Member

What about adding WrappedError fields to file.Error?

@hesining
Copy link
Contributor Author

What about adding WrappedError fields to file.Error?

it's a good idea. I'll try it later.

@hesining
Copy link
Contributor Author

#352
@antonmedv I try it , please check it.

@antonmedv
Copy link
Member

Released!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants