Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix two scenarios where null values were causing errors #473

Merged
merged 12 commits into from
Apr 10, 2019

Conversation

garemoko
Copy link
Contributor

Description

  • Fixes an issue where an error would occur if an assignment grade comment did not exist. Now in this scenario we just don't include the comment in the statement.
  • Fixes an issue where for essay type questions, a null response text would be included in the statement. Now this is replaced by an empty string to indicate that the response was an empty box.

Related Issues
None

PR Type
Fix

@garemoko
Copy link
Contributor Author

This hasn't been tested (other than the automatic tests)

@garemoko
Copy link
Contributor Author

I'm told that the quiz fix works, but the assignment grade does not and there's still a "assignfeedback_comments not found" error. I find this surprising given that it's inside a try-catch block. I'll need to take another look.

@garemoko
Copy link
Contributor Author

garemoko commented Apr 3, 2019

@ryansmith94 @davidpesce Please take a look at: https://github.com/xAPI-vle/moodle-logstore_xapi/blob/master/src/transformer/repos/MoodleRepository.php#L53

and

$gradecomment = $repo->read_record('assignfeedback_comments', [
'assignment' => $grade->assignment,
'grade' => $grade->id
])->commenttext;

In the MoodleRespository, is there any reason we need to throw an exception, rather than returning false, if a record is not found? For graded assignments, I don't believe we have any possible way of knowing before making the DB request whether or not there will be a comment entry in the DB.

@ryasmi
Copy link
Member

ryasmi commented Apr 4, 2019

Yeah we throw an error because it's a clearer error than a can't read X of false sort of error when you try to access properties on the returned record when it's not found. In cases where we might expect something to be missing we just need wrap the calls in a try catch.

@ryasmi
Copy link
Member

ryasmi commented Apr 4, 2019

Returning false is somewhat equivalent to returning null... "the billion dollar mistake"

@garemoko
Copy link
Contributor Author

garemoko commented Apr 4, 2019

Wrapping it in a try catch is what I tried but apparently the error is still getting through somehow.

I need to make some time to replicate this on my own Moodle so I can test properly. Or better, perhaps I can set up a test case for this.

@garemoko
Copy link
Contributor Author

garemoko commented Apr 8, 2019

Turns out that this was a namespace issue where the exception was being thrown as \Exception and I was catching \src\transformer\events\mod_assign\Exception. Changing Exception to \Exception fixed the issue.

@garemoko
Copy link
Contributor Author

garemoko commented Apr 8, 2019

@ryansmith94 this is now ready for review

@ryasmi
Copy link
Member

ryasmi commented Apr 8, 2019

Looks good to me @garemoko, think we should add some tests for this to avoid this becoming a problem again?

@garemoko
Copy link
Contributor Author

garemoko commented Apr 9, 2019

@ryansmith94 tests added.

Copy link
Member

@ryasmi ryasmi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice, tests look good thanks Andrew 👍

@ryasmi ryasmi merged commit 2ca21a0 into xAPI-vle:master Apr 10, 2019
@HT2Bot
Copy link
Member

HT2Bot commented Apr 10, 2019

🎉 This PR is included in version 4.2.3 🎉

The release is available on GitHub release

Your semantic-release bot 📦🚀

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants