Skip to content

up to 1.20 and Hold business error  #345

@hesining

Description

@hesining

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 ?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions