Uploaded image for project: 'Moodle'
  1. Moodle
  2. MDL-73876

Behat runs don't show exceptions stack trace

XMLWordPrintable

    • MOODLE_310_STABLE, MOODLE_311_STABLE, MOODLE_39_STABLE, MOODLE_400_STABLE
    • MOODLE_311_STABLE, MOODLE_400_STABLE
    • MDL-73876-master
    • Hide

      So you need to generate an exception in behat, lets break something

      • Find this line in code (<DIRROOT>/admin/tool/uploadcourse/classes/course.php around line 1007)

            protected function process_enrolment_data($course) {
        

      • Change it to

            protected function process_enrolment_data1($course) {
        

      • Run admin/tool/uploadcourse/tests/behat/create.feature Behat feature i.e

        php admin/tool/behat/cli/init.php
        vendor/bin/behat --config /home/ilyatregubov/moodles/stable_master/moodledata_behat/behatrun/behat/behat.yml /home/ilyatregubov/moodles/stable_master/moodle/admin/tool/uploadcourse/tests/behat/create.feature
        

      • Ensure you can see a stack trace:

                Dismiss this notification
                    
                 
                	* line 898 of /admin/tool/uploadcourse/classes/course.php: Error thrown
                	* line 209 of /admin/tool/uploadcourse/classes/processor.php: call to
                tool_uploadcourse_course->proceed()
                	* line 102 of /admin/tool/uploadcourse/index.php: call to
                tool_uploadcourse_processor->execute()
                 (Exception)
        

      Show
      So you need to generate an exception in behat, lets break something Find this line in code ( <DIRROOT>/admin/tool/uploadcourse/classes/course.php around line 1007) protected function process_enrolment_data($course) { Change it to protected function process_enrolment_data1($course) { Run admin/tool/uploadcourse/tests/behat/create.feature Behat feature i.e php admin/tool/behat/cli/init.php vendor/bin/behat --config /home/ilyatregubov/moodles/stable_master/moodledata_behat/behatrun/behat/behat.yml /home/ilyatregubov/moodles/stable_master/moodle/admin/tool/uploadcourse/tests/behat/create.feature Ensure you can see a stack trace: Dismiss this notification * line 898 of /admin/tool/uploadcourse/classes/course.php: Error thrown * line 209 of /admin/tool/uploadcourse/classes/processor.php: call to tool_uploadcourse_course->proceed() * line 102 of /admin/tool/uploadcourse/index.php: call to tool_uploadcourse_processor->execute() (Exception)

      This is something that it's happening since the night of the times (if I'm not wrong) and it's certainly annoying.

      For some reason, once behat detects that there is any debugging/exception message in the web page, it fails the step. And that's correct.

      But it seems that there is some problem being able to get the stack trace of the debugging/exception. So you've to go to apache logs (normally) and look for it there.

      For example, in apache logs... I get:

      [15-Feb-2022 06:02:04 Australia/Perth] Default exception handler: Exception - Warning: A non-numeric value encountered in [dirroot]/lib/grade/grade_item.php on line 1632 Debug: 
      Error code: generalexceptionmessage
      * line 157 of /lib/behat/lib.php: Exception thrown
      * line 1632 of /lib/grade/grade_item.php: call to behat_error_handler()
      * line 155 of /grade/report/singleview/classes/local/ui/finalgrade.php: call to grade_item->bounded_grade()
      * line 356 of /grade/report/singleview/classes/local/screen/screen.php: call to gradereport_singleview\local\ui\finalgrade->set()
      * line 389 of /grade/report/singleview/classes/local/screen/user.php: call to gradereport_singleview\local\screen\screen->process()
      * line 56 of /grade/report/singleview/lib.php: call to gradereport_singleview\local\screen\user->process()
      * line 124 of /grade/report/singleview/index.php: call to gradereport_singleview->process_data()
      

      And, in behat output I get:

      182 Scenario: I can bulk update grades. # /Users/stronk7/git_moodle/moodle/grade/report/singleview/tests/behat/singleview.feature:111
            And I press "Save"                # /Users/stronk7/git_moodle/moodle/grade/report/singleview/tests/behat/singleview.feature:117
              Moodle exception: Exception - Warning: A non-numeric value encountered in [dirroot]/lib/grade/grade_item.php on line 1632More information about this error
              
              Exception - Warning: A non-numeric value encountered in [dirroot]/lib/grade/grade_item.php on line 1632
              More information about this error
              
              
                  
              ×
                  
              Debug info: 
               
              Error code: generalexceptionmessage
               (Exception)
      

      And this is a paste of the HTML in the page, for reference / testing (though it's easy to throw an exception in any page and get the information):

      <div class="wibbler"><div data-rel="fatalerror" class="box py-3 errorbox alert alert-danger"><p class="errormessage">Exception - Warning: A non-numeric value encountered in [dirroot]/lib/grade/grade_item.php on line 1632</p><p class="errorcode"><a href="https://docs.moodle.org/400/en/error/moodle/generalexceptionmessage">More information about this error</a></p></div><div class="alert alert-danger alert-block fade in "  role="alert" data-aria-autofocus="true">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <strong>Debug info: </strong> <br />Error code: generalexceptionmessage
      </div><div class="alert alert-danger alert-block fade in "  role="alert" data-aria-autofocus="true">
          <button type="button" class="close" data-dismiss="alert">&times;</button>
          <strong>Stack trace: </strong> <ul style="text-align:left;"><li>line 157 of /lib/behat/lib.php: Exception thrown</li><li>line 1632 of /lib/grade/grade_item.php: call to behat_error_handler()</li><li>line 155 of /grade/report/singleview/classes/local/ui/finalgrade.php: call to grade_item-&gt;bounded_grade()</li><li>line 356 of /grade/report/singleview/classes/local/screen/screen.php: call to gradereport_singleview\local\ui\finalgrade-&gt;set()</li><li>line 389 of /grade/report/singleview/classes/local/screen/user.php: call to gradereport_singleview\local\screen\screen-&gt;process()</li><li>line 56 of /grade/report/singleview/lib.php: call to gradereport_singleview\local\screen\user-&gt;process()</li><li>line 124 of /grade/report/singleview/index.php: call to gradereport_singleview-&gt;process_data()</li></ul>
      </div>
      

      Surely it's because we don't "parse" the html correctly (maybe it has changed and in the past it was working)... but we should try to get the correct stack trace back to behat errors output. Only that way we have both the failing scenario and the stack trace together.

      Ciao

        1. MDL-73876_master.png
          MDL-73876_master.png
          37 kB
        2. MDL-73876_v311.png
          MDL-73876_v311.png
          39 kB
        3. MDL-73876_v400.png
          MDL-73876_v400.png
          40 kB

            ilyatregubov Ilya Tregubov
            stronk7 Eloy Lafuente (stronk7)
            Paul Holden Paul Holden
            Shamim Rezaie Shamim Rezaie
            John Edward Pedregosa John Edward Pedregosa
            Votes:
            1 Vote for this issue
            Watchers:
            6 Start watching this issue

              Created:
              Updated:
              Resolved:

                Estimated:
                Original Estimate - Not Specified
                Not Specified
                Remaining:
                Remaining Estimate - 0 minutes
                0m
                Logged:
                Time Spent - 2 hours, 22 minutes
                2h 22m

                  Error rendering 'clockify-timesheets-time-tracking-reports:timer-sidebar'. Please contact your Jira administrators.