Skip to content

Commit

Permalink
Make RException return as error
Browse files Browse the repository at this point in the history
  • Loading branch information
elct9620 committed Oct 3, 2024
1 parent ccf9746 commit 5fa279e
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 19 deletions.
7 changes: 0 additions & 7 deletions cmd/irb/main.go
Original file line number Diff line number Diff line change
Expand Up @@ -31,13 +31,6 @@ func main() {
}

ret, err := mrb.LoadString(line)

// NOTE: ret may be error
errRet, ok := ret.(error)
if ok {
err = errRet
}

if err != nil {
fmt.Println(err)
} else {
Expand Down
18 changes: 14 additions & 4 deletions godogs_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -22,11 +22,21 @@ const SuiteSuccessCode = 0
type RubyFeature struct {
mrb *mruby.State
ret mruby.Value
exc mruby.RException
}

func (feat *RubyFeature) iExecuteRubyCode(code *godog.DocString) (err error) {
feat.ret, err = feat.mrb.LoadString(code.Content)
return
func (feat *RubyFeature) iExecuteRubyCode(code *godog.DocString) error {
ret, err := feat.mrb.LoadString(code.Content)
if err != nil {
exc, ok := err.(mruby.RException)
if !ok {
return err
}
feat.exc = exc
}
feat.ret = ret

return nil
}

func (feat *RubyFeature) thereShouldReturnInteger(expected int) error {
Expand Down Expand Up @@ -179,7 +189,7 @@ func (feat *RubyFeature) thereShouldReturnAHash(doc *godog.DocString) error {
}

func (feat *RubyFeature) theExceptionMessageShouldBe(expected string) error {
exc, ok := feat.ret.(mruby.RException)
exc, ok := feat.exc.(mruby.RException)

Check failure on line 192 in godogs_test.go

View workflow job for this annotation

GitHub Actions / lint

S1040: type assertion to the same type: feat.exc already has type mruby.RException (gosimple)

if !ok {
return fmt.Errorf("expected exception, got %T", feat.ret)
Expand Down
9 changes: 1 addition & 8 deletions vm.go
Original file line number Diff line number Diff line change
Expand Up @@ -41,14 +41,7 @@ func (mrb *State) VmRun(proc RProc, self Value) (Value, error) {
func (mrb *State) VmExec(proc RProc, code *insn.Sequence) (ret Value, err error) {
defer func() {
if r := recover(); r != nil {
ret = nil

switch v := r.(type) {
case RException:
ret = v
case error:
err = v
}
err = r.(error)
}
}()

Expand Down

0 comments on commit 5fa279e

Please sign in to comment.