Skip to content

xpcall with error in error handler returns (nil, nil) #452

@mzki

Description

@mzki

You must post issues only here. Questions, ideas must be posted in discussions.

  • GopherLua is a Lua5.1 implementation. You should be familiar with Lua programming language. Have you read Lua 5.1 reference manual carefully?
  • GopherLua is a Lua5.1 implementation. In Lua, to keep it simple, it is more important to remove functionalities rather than to add functionalities unlike other languages . If you are going to introduce some new cool functionalities into the GopherLua code base and the functionalities can be implemented by existing APIs, It should be implemented as a library.

Please answer the following before submitting your issue:

  1. What version of GopherLua are you using? : 2b3f02d
  2. What version of Go are you using? : go version go1.19.12 linux/amd64
  3. What operating system and processor architecture are you using? : See 2.
  4. What did you do? :
  5. What did you expect to see? :
    xpcall with error in error handler returns (false, error-object).
/ # lua
Lua 5.1.5  Copyright (C) 1994-2012 Lua.org, PUC-Rio
> ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
> print(ok, msg)
false   error in error handling
> function test()
>>   xpcall(function() error("fn") end, function(err) error("handler") end)
>>   error("expected to reach this")
>> end
> test()
stdin:3: expected to reach this
stack traceback:
        [C]: in function 'error'
        stdin:3: in function 'test'
        stdin:1: in main chunk
        [C]: ?
>
  1. What did you see instead? :
    xpcall with error in error handler returns (nil, nil).
    In addition, xpcall exits current function scope and interpreter does not execute next line.
/workspaces/gopher-lua/cmd/glua# ./glua 
GopherLua 0.1 Copyright (C) 2015 -2017 Yusuke Inuzuka
> ok, msg = xpcall(function() error("fn") end, function(err) error("handler") end)
> print(ok, msg)
nil     nil
> function test()
>>   xpcall(function() error("fn") end, function(err) error("handler") end)
>>   error("expected to reach this")
>> end
> test()
> 

Although the behavior of xpcall with error in error handler is not well described in the reference, but it is better to be compatible with CLua5.1 behavior.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions