Skip to content

BuiltIn: Call Method loses traceback if calling the method fails #4476

Closed

Description

@kbogineni

I see the below call is not logging traceback on failure and throwing the error message instead.
Call method ${obj} ${method} ${args}

It would be great to log the traceback incase of any failure, it will be helpful to identify the issue soon.

Need the fix in version 4.1

Activity

  1. changed the title [-]Call method is not logging the traceback[/-] [+]Call method is not logging the traceback on failure[/+] on Sep 23, 2022
  2. kbogineni commented on Sep 23, 2022

    @kbogineni
    Author
  3. pekkaklarck commented on Sep 25, 2022

    @pekkaklarck
    Member

    Could you please clarify the problem?

  4. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    Could you please clarify the problem?

    if call_method is failing with an error then we are not getting trace back of the failure, we are just getting the failure message and it is hard to debug such failures

  5. pekkaklarck commented on Sep 26, 2022

    @pekkaklarck
    Member

    Do you mean BuiltIn.call_method or something you created? Have you tried running tests with --loglevel debug?

  6. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    Do you mean BuiltIn.call_method or something you created? Have you tried running tests with --loglevel debug?

    It is with call_method and I tried with --loglevel debug also but no use

  7. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    call_method is raising the exception but logging the traceback as None

  8. pekkaklarck commented on Sep 26, 2022

    @pekkaklarck
    Member

    It's true that if I have something like

    *** Test Cases ***
    Example
       Call method    string    upper    bad

    the traceback is just this:

    Traceback (most recent call last):
      None
    RuntimeError: Calling method 'upper' failed: TypeError: upper() takes no arguments (1 given)
    

    I don't think there could be any traceback to show in this case, though. You don't get anything more if you run same thing directly in Python:

    >>> 'string'.upper('bad')
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
    TypeError: str.upper() takes no arguments (1 given)

    Do you have a concrete example where there should be a traceback but isn't?

  9. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    Yes, Assume that we have one python module and I have called a method and want to see the at which line of the code the failure appeared?? how to see at which line it is failed

  10. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    If you see the above example the traceback is given(if you execute python directly)

  11. pekkaklarck commented on Sep 26, 2022

    @pekkaklarck
    Member

    Yeah, there's problem if the exception occurs somewhere else. The reason is that the original traceback is lost because we raise a new RuntimeError if calling the method fails. Python 3 makes it possible to attach context information to the exception like raise NewError from old but it seems that our traceback formatting code needs to be enhanced slightly as well. Fixing this is so easy that I can still include it into RF 5.1.

    Notice that the fix won't be backported to RF 4.1 or any other older version. If you need to use older versions and must have a fix, you need to patch your installation yourself. Alternatively, and probably better, you should change your code into a library and call those methods as keywords.

  12. added this to the v5.1 milestone on Sep 26, 2022
  13. pekkaklarck commented on Sep 26, 2022

    @pekkaklarck
    Member

    A trivial fix would be just reraising the original exception, but then the error message would change and that could cause backwards compatibility problems. Better enhance the code so that traceback is preserved.

  14. changed the title [-]Call method is not logging the traceback on failure[/-] [+]BuiltIn: `Call Method` loses traceback if calling the method fails[/+] on Sep 26, 2022
  15. kbogineni commented on Sep 26, 2022

    @kbogineni
    Author

    Thanks. We can fix it in version 5 only in that case. We will upgrade robot version

  16. pekkaklarck commented on Sep 27, 2022

    @pekkaklarck
    Member

    It would actually be enough to fix only the traceback formatting code to get the original traceback included. The problem there is that if the exception has no normal traceback to show, traceback of the original exception isn't shown either. This was a mistake made when adding support for chained exceptions in general in RF 5.0 (#4039). I decided to add from err to call_method anyway because it makes the resulting error a bit better.

  17. kbogineni commented on Sep 27, 2022

    @kbogineni
    Author

    Thanks

  18. added theissue type on Dec 9, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Type

    Projects

    No projects

      Milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions