[yast-devel] Ruby-bindings and exception
Hi YaST hackers, there is problem with exceptions from ruby modules. Now if risen, yast crash. I found this behavior quite annoying and it should be improved. I can do it, question is what is correct behavior. Does anyone have suggestion? In yast++ we have now error variable and catch exceptions. So I can in ruby bindings ( and only in bindings so ruby code is not affected ) extend class by method that return message of last exception. So you can run code as if (Module::run == nil) y2error ("Problem with run %1",Module.yast_error); I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem? And how connection to C++ code behave? Thanks for attention Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Dne Po 13. února 2012 19:19:56, Josef Reidinger napsal(a):
Hi YaST hackers, there is problem with exceptions from ruby modules. Now if risen, yast crash. I found this behavior quite annoying and it should be improved. I can do it, question is what is correct behavior. Does anyone have suggestion? In yast++ we have now error variable and catch exceptions. So I can in ruby bindings ( and only in bindings so ruby code is not affected ) extend class by method that return message of last exception. So you can run code as if (Module::run == nil) y2error ("Problem with run %1",Module.yast_error);
I think this is basically only option from YaST side; catch exception in ruby- bindings layer and save some error exception message (just do not call it 'yast_error', better, exception_message or last_error). Who would need to set that variable? YLib? Or could it be set by ruby-bindings from the exception message it catches?
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash Jiri -- Jiri Suchomel SUSE LINUX, s.r.o. e-mail: jsuchome@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Praha 9, Czech Republic http://www.suse.cz -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 02/14/2012 09:13 AM, Jiri Suchomel wrote:
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings. Having the last_error or maybe even last_exception (with details) method would be definitely a good approach. Lukas -- Lukas Ocilka, Appliances Department SUSE LINUX s.r.o., Praha -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings.
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach. ... what about multi-thread environment? Single variable can lead to information loss.
Michal -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 14 Feb 2012 10:02:01 +0100 "Michal Filka" <michal.filka@suse.cz> wrote:
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings.
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach. ... what about multi-thread environment? Single variable can lead to information loss.
Michal
Good point, if we use object, then it will be easy to inject just called object, but we use modules, so it is shared. But because ruby modules is usually just for saving configuration, then it is not protected for multi-thread I think. ( At least I never try to run two yast instances and try to save two different configuration in one module. I expect mess ). In usual two thread where one is for UI and second for data handling it should work fine. Josef -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 14 Feb 2012 09:57:54 +0100 Lukas Ocilka <lukas.ocilka@suse.cz> wrote:
On 02/14/2012 09:13 AM, Jiri Suchomel wrote:
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings.
Yes, I automatically expect it.
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach.
I think that message should be enough, backtrace should go just to logs. Josef
Lukas
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On 02/14/2012 10:23 AM, Josef Reidinger wrote:
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach.
I think that message should be enough, backtrace should go just to logs.
We have a special logfile for that: /var/log/YaST2/signal L. -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 14 Feb 2012 10:26:28 +0100 Lukas Ocilka <lukas.ocilka@suse.cz> wrote:
On 02/14/2012 10:23 AM, Josef Reidinger wrote:
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach.
I think that message should be enough, backtrace should go just to logs.
We have a special logfile for that: /var/log/YaST2/signal
L.
I think we should not confuse such file with output from ruby-bindings. Purpose of this file is to check problem e.g. segfaults, division by zero etc. On other hand, exception in ruby is part of common workflow like missing file, permissions, unexpected output etc. I think that common yast log with proper level ( error ) should be enough. Josef -- Josef Reidinger Software Engineer Appliance Department SUSE LINUX, s. r. o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic jreidinger@suse.com SUSE -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Dne 14.2.2012 09:57, Lukas Ocilka napsal(a):
On 02/14/2012 09:13 AM, Jiri Suchomel wrote:
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings.
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach.
When pkg-bindings catch an exception from libzypp the invoked Pkg:: call returns nil and Pkg::LastError() and Pkg::LastErrorDetails() return the details about the error. Libzypp exceptions are automatically logged by libzypp when they are thrown (pkg-bindings do not have to do anything special). I think a similar way can be used also in Ruby bindings. -- Ladislav Slezák Appliance department / YaST Developer Lihovarská 1060/12 190 00 Prague 9 / Czech Republic tel: +420 284 028 960 lslezak@suse.com SUSE -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 14 Feb 2012 17:27:31 +0100 Ladislav Slezak <lslezak@suse.cz> wrote:
Dne 14.2.2012 09:57, Lukas Ocilka napsal(a):
On 02/14/2012 09:13 AM, Jiri Suchomel wrote:
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash
IMO it would be nice if error was logged anytime an exception is caught by ruby-bindings.
Having the last_error or maybe even last_exception (with details) method would be definitely a good approach.
When pkg-bindings catch an exception from libzypp the invoked Pkg:: call returns nil and Pkg::LastError() and Pkg::LastErrorDetails() return the details about the error.
Libzypp exceptions are automatically logged by libzypp when they are thrown (pkg-bindings do not have to do anything special).
I think a similar way can be used also in Ruby bindings.
That sounds interesting. I just need to clarify two questions here: 1) you control Pkg...but ruby bindings doesn't control module written in Ruby, so we should use some specific to not overwrite module method...maybe LastException is good enough. 2) what you include in LastErrorDetails? backtrace? Does anyone use it? Josef
--
Ladislav Slezák Appliance department / YaST Developer Lihovarská 1060/12 190 00 Prague 9 / Czech Republic tel: +420 284 028 960 lslezak@suse.com SUSE
-- Josef Reidinger Software Engineer Appliance Department SUSE LINUX, s. r. o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic jreidinger@suse.com SUSE -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Dne 15.2.2012 13:13, Josef Reidinger napsal(a):
That sounds interesting. I just need to clarify two questions here:
1) you control Pkg...but ruby bindings doesn't control module written in Ruby, so we should use some specific to not overwrite module method...maybe LastException is good enough.
Um, I don't know how actually ruby bindings work, but I think you should catch the exceptions at the highest level (in C++) if that's possible... All calls in pkg-bindings are wrapped in a generic catch(...) which catches all exceptions (so yast doesn't crash if there is an unknown problem or missing catch statement).
2) what you include in LastErrorDetails? backtrace? Does anyone use it?
Um, unfortunately it is currently not used :-( It could contain libzypp history e.g. DNS name resolving problem -> file FOO download failed -> repo refresh failed. Libzypp history is a kind of backtrace, but suitable for end users (no technical details like line numbers and function names - this can be found in the log). Just high level overview what went wrong like in the example above... But currently the exception history is part of the LastErrorMessage() because YCP scripts do not use LastErrorDetails() at all (grep in SVN trunk just found 3 calls in all yast modules). After adding libzypp history support to LastErrorDetails() I would had to change all YCP code using LastError() to use also LastErrorMessage(). I chose the easier way and simply added the history to LastError()... -- Best Regards Ladislav Slezák Yast Developer ------------------------------------------------------------------------ SUSE LINUX, s.r.o. e-mail: lslezak@suse.cz Lihovarská 1060/12 tel: +420 284 028 960 190 00 Prague 9 fax: +420 284 028 951 Czech Republic http://www.suse.cz/ -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
On Tue, 14 Feb 2012 09:13:16 +0100 Jiri Suchomel <jsuchome@suse.cz> wrote:
Dne Po 13. února 2012 19:19:56, Josef Reidinger napsal(a):
Hi YaST hackers, there is problem with exceptions from ruby modules. Now if risen, yast crash. I found this behavior quite annoying and it should be improved. I can do it, question is what is correct behavior. Does anyone have suggestion? In yast++ we have now error variable and catch exceptions. So I can in ruby bindings ( and only in bindings so ruby code is not affected ) extend class by method that return message of last exception. So you can run code as if (Module::run == nil) y2error ("Problem with run %1",Module.yast_error);
I think this is basically only option from YaST side; catch exception in ruby- bindings layer and save some error exception message (just do not call it 'yast_error', better, exception_message or last_error). Who would need to set that variable? YLib? Or could it be set by ruby-bindings from the exception message it catches?
ruby-bindings should set it. YLib shouls behave like modern library and use exceptions. Name is not important it just need to be unique ( if there is existing ruby module with such name so we don't break it.
I welcome any other suggestions or comments. Also it would be nice to have uniform way....how python bindings solve such problem?
I do not think it is solved in python-bindings. I've just tested: when exception is raised, YaST logs an error. But it does not crash
It can be also option, but it prevent to have user friendly modules. Josef
Jiri
-- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
Hi, I just implement first version of handling of exception. It is now just in svn. example of usage is in [0] with code in [1]. I welcome any comments or suggestion how to improve it. Josef P.S. As bonus as fix one memory leak which happen when exception will be risen ( now because yast cause on uninitialized value it not shown ) [2] [0] http://svn.opensuse.org/svn/yast/trunk/ruby-bindings/tests/ycp/ruby_from_ycp... [1] http://svn.opensuse.org/svn/yast/trunk/ruby-bindings/tests/ycp/InRuby.rb [2] http://svn.opensuse.org/viewvc/yast/trunk/ruby-bindings/src/ruby/YRuby.cc?r1... -- Josef Reidinger Software Engineer Appliance Department SUSE LINUX, s. r. o. Lihovarska 1060/12 190 00 Praha 9 Czech Republic jreidinger@suse.com SUSE -- To unsubscribe, e-mail: yast-devel+unsubscribe@opensuse.org To contact the owner, e-mail: yast-devel+owner@opensuse.org
participants (5)
-
Jiri Suchomel
-
Josef Reidinger
-
Ladislav Slezak
-
Lukas Ocilka
-
Michal Filka