Cursor rule
.cursor/rules/moodle-error-handling.mdc[object Object]
Cursor rules
Quality
50/100
Scores the file, not the repository.Length
343 words
5 headings · 1 code blocksRepository
4
— · pushed 2 days agoLast changed
3 days ago
First indexed 3 days ago.123456# Moodle Error Handling78## Purpose9Ensure consistent and proper error handling across all Moodle PHP code for better debugging and user experience.1011## Instructions12When implementing error handling in Moodle PHP code, follow these practices:13141. **Use Moodle Exceptions**: Use `moodle_exception` and specific exception types152. **Parameter Validation**: Use `required_param()`, `optional_param()` with proper validation163. **Debugging**: Use `debugging()` for development, `error_log()` for critical errors174. **User Feedback**: Provide meaningful error messages using language strings185. **Graceful Degradation**: Handle errors gracefully without breaking the user experience196. **Logging**: Use Moodle's logging system for important events and errors207. **Context Information**: Include relevant context in error messages218. **Error Recovery**: Implement recovery mechanisms where possible2223## Examples2425```php26<?php27// File: ./includes/error_handling_example.php2829/**30 * Example of proper error handling in Moodle31 */32function process_user_action($userid, $action) {33 global $DB, $USER;3435 try {36 // Parameter validation37 $userid = required_param('userid', PARAM_INT);38 $action = required_param('action', PARAM_ALPHA);3940 // Validate user exists41 $user = $DB->get_record('user', ['id' => $userid], '*', MUST_EXIST);4243 // Check permissions44 if (!has_capability('moodle/user:edit', context_user::instance($userid))) {45 throw new moodle_exception('nopermission', 'core');46 }4748 // Perform action with error handling49 switch ($action) {50 case 'update':51 $result = update_user_profile($userid);52 break;53 case 'delete':54 $result = delete_user_data($userid);55 break;56 default:57 throw new moodle_exception('invalidaction', 'core');58 }5960 // Log successful action61 \core\event\user_action_performed::create([62 'objectid' => $userid,63 'relateduserid' => $USER->id,64 'other' => ['action' => $action]65 ])->trigger();6667 return $result;6869 } catch (dml_exception $e) {70 // Database errors71 debugging('Database error: ' . $e->getMessage(), DEBUG_DEVELOPER);72 throw new moodle_exception('databaseerror', 'core');7374 } catch (moodle_exception $e) {75 // Re-throw Moodle exceptions76 throw $e;7778 } catch (Exception $e) {79 // Unexpected errors80 error_log('Unexpected error in process_user_action: ' . $e->getMessage());81 throw new moodle_exception('unknownerror', 'core');82 }83}8485/**86 * Graceful error handling with user feedback87 */88function display_user_data($userid) {89 try {90 $userdata = get_user_data($userid);91 echo format_string($userdata->name);9293 } catch (moodle_exception $e) {94 // Show user-friendly error95 echo html_writer::div(96 get_string('error_loading_user', 'core'),97 'alert alert-warning'98 );99100 // Log detailed error for administrators101 debugging('Error loading user data: ' . $e->getMessage(), DEBUG_DEVELOPER);102 }103}104```105106## Exceptions107- Critical system errors may require different handling approaches108- Third-party integrations may have specific error handling requirements109
Also in WisdmLabs/moodle-local_edwiserreports-free
Diff this repo’s formatsOne repository carrying more than one format is the comparison this product exists for: does anyone actually write different content in each file, or is one a copy of the other?
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-ajax-and-js-integration.mdc · 4 | Cursor rules | agent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-configuration-management.mdc · 4 | Cursor rules | agent-behaviour | 36/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-database-patterns.mdc · 4 | Cursor rules | styledatabaseagent-behaviour | 54/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-events-and-callbacks.mdc · 4 | Cursor rules | agent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-file-and-media-handling.mdc · 4 | Cursor rules | agent-behaviour | 36/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-internationalization.mdc · 4 | Cursor rules | agent-behaviour | 36/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-performance-optimization.mdc · 4 | Cursor rules | performanceagent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-php-coding-standards.mdc · 4 | Cursor rules | agent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-plugin-structure.mdc · 4 | Cursor rules | archagent-behaviour | 54/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-scheduled-tasks.mdc · 4 | Cursor rules | agent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-security-practices.mdc · 4 | Cursor rules | securityagent-behaviour | 50/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-testing-and-quality.mdc · 4 | Cursor rules | testtesting-strategyagent-behaviour | 54/100 | 3 days ago | |
| WisdmLabs/moodle-local_edwiserreports-free.cursor/rules/moodle-web-services-and-api.mdc · 4 | Cursor rules | apiagent-behaviour | 50/100 | 3 days ago |
Diff against .cursor/rules/moodle-ajax-and-js-integration.mdc Diff against .cursor/rules/moodle-configuration-management.mdc Diff against .cursor/rules/moodle-database-patterns.mdc Diff against .cursor/rules/moodle-events-and-callbacks.mdc Diff against .cursor/rules/moodle-file-and-media-handling.mdc Diff against .cursor/rules/moodle-internationalization.mdc Diff against .cursor/rules/moodle-performance-optimization.mdc Diff against .cursor/rules/moodle-php-coding-standards.mdc Diff against .cursor/rules/moodle-plugin-structure.mdc Diff against .cursor/rules/moodle-scheduled-tasks.mdc Diff against .cursor/rules/moodle-security-practices.mdc Diff against .cursor/rules/moodle-testing-and-quality.mdc Diff against .cursor/rules/moodle-web-services-and-api.mdc
Similar configs
Same format, overlapping stack, ranked by quality.
| Repository | Format | Stack | Covers | Score | Changed |
|---|---|---|---|---|---|
| hiromaily/go-crypto-wallet.cursor/rules/typescript.mdc · 126 | Cursor rules | setupbuildtestlint-format+6 | 100/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/10-hermes-api.mdc · 45 | Cursor rules | testlint-formatstylearch+5 | 100/100 | 3 days ago | |
| markstev/mark-starter.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+6 | 99/100 | 3 days ago | |
| Allymahmoud/case-intake-platform.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| deifos/clipmira-subtitles.cursor/rules/frontend.mdc · 1 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| dodgecfr/combatfilms-webapp.cursor/rules/frontend.mdc · 0 | Cursor rules | setuptestlint-formatstyle+7 | 99/100 | 3 days ago | |
| langflow-ai/langflow.cursor/rules/docs_development.mdc · 153k | Cursor rules | setupbuildtestlint-format+7 | 97/100 | 3 days ago | |
| TechSquidTV/Hermes.cursor/rules/20-hermes-api-tests.mdc · 45 | Cursor rules | teststyletesting-strategysecurity+3 | 97/100 | 3 days ago |
