Code Monkey home page Code Monkey logo

Comments (18)

erikh avatar erikh commented on August 28, 2024 1

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

Here's the simple way to reproduce it:

package main

import (
	"fmt"

	mruby "github.com/mitchellh/go-mruby"
)

var testClass *mruby.Class

func createException(m *mruby.Mrb, msg string) mruby.Value {
	val, err := m.Class("Exception", nil).New(mruby.String(msg))
	if err != nil {
		panic(fmt.Sprintf("could not construct exception for return: %v", err))
	}

	return val
}

func testFunc(m *mruby.Mrb, self *mruby.MrbValue) (mruby.Value, mruby.Value) {
	args := m.GetArgs()
	fmt.Println(args)

	t, err := testClass.New()
	if err != nil {
		return nil, createException(m, err.Error())
	}

	argv := []mruby.Value{}
	for _, arg := range args {
		argv = append(argv, mruby.Value(arg))
	}
	v, err := t.Call("dotest!", argv...)
	if err != nil {
		return nil, createException(m, err.Error())
	}

	return v, nil
}

func doTestFunc(m *mruby.Mrb, self *mruby.MrbValue) (mruby.Value, mruby.Value) {
	args := m.GetArgs()
	fmt.Println(args)
	if len(args) > 1 {
		err := createException(m, "Fail us!")
		fmt.Println("createException returned")
		return nil, err
	}
	return nil, nil
}

func main() {
	mrb := mruby.NewMrb()
	mrb.DisableGC()

	testClass = mrb.DefineClass("TestClass", nil)
	testClass.DefineMethod("dotest!", doTestFunc, mruby.ArgsReq(0)|mruby.ArgsOpt(3))

	mrb.TopSelf().SingletonClass().DefineMethod("test", testFunc, mruby.ArgsReq(0)|mruby.ArgsOpt(3))

	if _, err := mrb.LoadString("test()"); err != nil {
		fmt.Printf("Error: %v\n", err)
	}
	if _, err := mrb.LoadString("test(1)"); err != nil {
		fmt.Printf("Error: %v\n", err)
	}
	// Next call will result in a panic
	if _, err := mrb.LoadString("test(1, 2)"); err != nil {
		fmt.Printf("Error: %v\n", err)
	}
}

ping @erikh

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

The reason I'm doing this level of nesting, is because kubeplay is a DSL, which has simple methods one calls in a REPL, which in turns create objects and call methods on them.

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

The stack trace is:

[]
[]
[1]
[1]
[1 2]
[1 2]
createException returned
fatal error: exitsyscall: syscall frame is no longer valid

runtime stack:
runtime.throw(0x4139cec, 0x2d)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/panic.go:566 +0x95
runtime.exitsyscall.func1()
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/proc.go:2470 +0x36
runtime.systemstack(0x7fff5fbff6e0)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/asm_amd64.s:298 +0x79
runtime.mstart()
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/proc.go:1079

goroutine 1 [syscall, locked to thread]:
runtime.cgocall(0x408e840, 0xc420051928, 0xc400000000)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/cgocall.go:131 +0x110 fp=0xc4200518d0 sp=0xc420051890
github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby._Cfunc_mrb_funcall_argv(0x4600020, 0x5005640, 0x8, 0x20000028f, 0xc42008a380, 0x0, 0x0)
	??:0 +0x5d fp=0xc420051928 sp=0xc4200518d0
github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby.(*MrbValue).call(0xc42008a340, 0x4134526, 0x7, 0xc42008a360, 0x2, 0x2, 0x0, 0x0, 0x0, 0x0, ...)
	/Users/ilya/Code/kubeplay/src/github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby/value.go:94 +0x5e0 fp=0xc420051a28 sp=0xc420051928
github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby.(*MrbValue).Call(0xc42008a340, 0x4134526, 0x7, 0xc42008a360, 0x2, 0x2, 0x1, 0x2, 0x0)
	/Users/ilya/Code/kubeplay/src/github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby/value.go:47 +0x7c fp=0xc420051a90 sp=0xc420051a28
main.testFunc(0xc420088068, 0xc42008a2c0, 0x290, 0xc42009e098, 0x0, 0x0)
	/Users/ilya/Code/kubeplay/src/github.com/errordeveloper/reproduce-go-mruby-issue-49/main.go:33 +0x27f fp=0xc420051b58 sp=0xc420051a90
github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby.goMRBFuncCall(0x4600020, 0x7fff5fbfe558, 0x7fff5fbfe548, 0x0, 0x0)
	/Users/ilya/Code/kubeplay/src/github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby/func.go:58 +0x1a8 fp=0xc420051c20 sp=0xc420051b58
github.com/errordeveloper/reproduce-go-mruby-issue-49/vendor/github.com/mitchellh/go-mruby._cgoexpwrap_2c571e600d93_goMRBFuncCall(0x4600020, 0x7fff5fbfe558, 0x7fff5fbfe548, 0x0, 0x0)
	??:0 +0x51 fp=0xc420051c68 sp=0xc420051c20
runtime.call64(0x0, 0x7fff5fbfe448, 0x7fff5fbfe4e8, 0x28)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/asm_amd64.s:480 +0x4c fp=0xc420051cb8 sp=0xc420051c68
runtime.cgocallbackg1(0x0)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/cgocall.go:283 +0x19d fp=0xc420051d30 sp=0xc420051cb8
runtime.cgocallbackg(0xc420051dc0)
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/cgocall.go:170 +0x84 fp=0xc420051d98 sp=0xc420051d30

goroutine 17 [syscall, locked to thread]:
runtime.goexit()
	/Users/ilya/Library/Local/Homebrew/Cellar/go/1.7.1/libexec/src/runtime/asm_amd64.s:2086 +0x1

It points to value.go:94.

from go-mruby.

erikh avatar erikh commented on August 28, 2024

Please try with this branch. I will explain more on the func PR: https://github.com/mitchellh/go-mruby/compare/master...erikh:fix-pointers?expand=1

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

@erikh thank you!! I'll test now.

from go-mruby.

erikh avatar erikh commented on August 28, 2024

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

Yes, I've noticed that exceptions broke.

Also, something else seems to be broken. My code appears to hit this, which is kindda expected to be virtually unreachable...

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

My code appears to hit this, which is kindda expected to be virtually unreachable...

The way that code compares pointers may not be idea, suggestions are very welcome 👍

from go-mruby.

erikh avatar erikh commented on August 28, 2024

from go-mruby.

erikh avatar erikh commented on August 28, 2024

OK, I was very, very wrong about what was triggering this.

Good news is that now I have a branch that not only fixes it, but passes on master's test suite too. :D

https://github.com/mitchellh/go-mruby/compare/master...erikh:fix-exception-propagation?expand=1

Here's the individual commit so you can see what's going on: 14b4b06

Give it a shot please?

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

It works for the test program above, and now it prints the exception as expected, which it didn't when I tested 922be14.

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

So 922be14 is not needed at all?

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

I've tested with kubeplay, and original code path where I found this appears to work well. Yet, I seem to hit this panic when I get an exception from a block that is instance_eval'ed. I will try and figure it out, but probably not tonight.

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

This what caused this originally and works now:

kubeplay (namespace="*")> pods []
+++ Execute: pods []
args=[[]]
+++ Error: Not yet implemented!

I've written new thing called with_labels yesterday, and it takes a block that is instance_eval'ed to provide a funky little DSL for building label expressions with Ruby syntax, e.g. with_labels { label("foo") =~ %w(foo.baz foo.bar); label("boom").defined?; }, it also has predefined shortcuts for @app and @name...

Here is what should had been an exception about undefined method foo:

kubeplay (namespace="*")> with_labels { foo }
+++ Execute: with_labels 
fatal error: exitsyscall: syscall frame is no longer valid
...

Also @foo is nil and has now defined? method, and thereby causes an exception too:

kubeplay (namespace="*")> with_labels { @app.defined? ; @foo.defined? ; }
+++ Execute: with_labels 
{app  []}
fatal error: exitsyscall: syscall frame is no longer valid
...

The code is in master branch of kubeplay, see rubykube/class.labels.go and rubykube/verbs.go.

from go-mruby.

erikh avatar erikh commented on August 28, 2024

Can you try on the latest commits to that branch, please?

from go-mruby.

errordeveloper avatar errordeveloper commented on August 28, 2024

@erikh awesome work! It now works as expected in both cases where it previously failed :)

kubeplay (namespace="*")> pods []
+++ Execute: pods []
+++ Error: Not yet implemented!
kubeplay (namespace="*")> with_labels { foo }
+++ Execute: with_labels 
+++ Error: undefined method 'foo' for #<LabelCollector:0x9002880>
kubeplay (namespace="*")> with_labels { @foo.defined? }
+++ Execute: with_labels 
+++ Error: undefined method 'defined?' for nil
kubeplay (namespace="*")> ^D

from go-mruby.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.