Skip to content

Error pages refactor#768

Merged
rosado merged 21 commits into
mainfrom
rosado/189-error-pages
Jan 15, 2025
Merged

Error pages refactor#768
rosado merged 21 commits into
mainfrom
rosado/189-error-pages

Conversation

@rosado
Copy link
Copy Markdown
Contributor

@rosado rosado commented Jan 8, 2025

What type of PR is this? (check all applicable)

  • Refactor

Description

This PR removes all the errorPages/xxx.html templates and replaces them with a single error template. It introduces a Error subclass MiddlewareError that should be use when we need to force the page to display specific error.

The error pages include stack traces and (when relevant) schema validation issues. Both are displayed only on when the environment process.env.NODE_ENV || process.env.ENVIRONMENT is not set to production. Also, no errors details are shown on 404 page - it would be noise.

Also: the templates for URL/file upload errors in the check tool provide /check link to start over (it used to be /url and /upload).

Related Tickets & Documents

Note: #762 should be merged first.

QA Instructions, Screenshots, Recordings

See example URL for a 400 error page

image

Note: Schema Issues are only present when the error was cause by invalid schema.

Added/updated tests?

  • Yes

QA sign off

  • Code has been checked and approved
  • Design has been checked and approved
  • Product and business logic has been checked and proved

Summary by CodeRabbit

Release Notes

  • New Features

    • Added contact configuration with support email for reporting issues
    • Enhanced error handling with new MiddlewareError class
    • Improved error page rendering with more detailed context
  • Bug Fixes

    • Updated routing and navigation for error scenarios
    • Refined error message specificity across various middleware components
  • Documentation

    • Simplified error templates
    • Removed deprecated error page templates
  • Refactor

    • Standardised error handling mechanisms
    • Updated configuration validation processes
  • Chores

    • Updated test suites to reflect new error handling approach
    • Cleaned up unused code and imports

These changes improve the application's error reporting, user guidance, and overall error management strategy.

@coderabbitai
Copy link
Copy Markdown
Contributor

coderabbitai Bot commented Jan 8, 2025

Walkthrough

This pull request introduces a comprehensive overhaul of error handling and configuration management across the application. The changes focus on creating a more robust, informative error reporting mechanism that provides detailed error information in non-production environments. A new contact configuration has been added, and error templates have been consolidated into a single, more flexible template. The implementation includes enhanced error classes, improved middleware error handling, and a more structured approach to displaying technical errors.

Changes

File Change Summary
config/default.yaml Added new contact section with issues.email configuration
config/util.js Added contact schema validation and new validateConfig function
src/utils/errors.js Introduced MiddlewareError class and errorTemplateContext function
Multiple middleware files Updated error handling to use new MiddlewareError
Error page templates Consolidated into error.njk, removed individual error templates

Assessment against linked issues

Objective Addressed Explanation
Display technical errors in non-production environments
Consolidate error page templates
Add debug flag for production

Suggested labels

bug, enhancement, tech debt

Suggested reviewers

  • CharliePatterson
  • DilwoarH

Poem

🐰 In the realm of code, where errors once did hide,
A rabbit's magic wand swept errors aside
With context clear and messages so bright,
Debugging becomes a delightful delight!
Error pages now sing, no mystery in sight 🔍

Finishing Touches

  • 📝 Generate Docstrings (Beta)

Thank you for using CodeRabbit. We offer it for free to the OSS community and would appreciate your support in helping us grow. If you find it useful, would you consider giving us a shout-out on your favorite social media?

❤️ Share
🪧 Tips

Chat

There are 3 ways to chat with CodeRabbit:

  • Review comments: Directly reply to a review comment made by CodeRabbit. Example:
    • I pushed a fix in commit <commit_id>, please review it.
    • Generate unit testing code for this file.
    • Open a follow-up GitHub issue for this discussion.
  • Files and specific lines of code (under the "Files changed" tab): Tag @coderabbitai in a new review comment at the desired location with your query. Examples:
    • @coderabbitai generate unit testing code for this file.
    • @coderabbitai modularize this function.
  • PR comments: Tag @coderabbitai in a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:
    • @coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.
    • @coderabbitai read src/utils.ts and generate unit testing code.
    • @coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
    • @coderabbitai help me debug CodeRabbit configuration file.

Note: Be mindful of the bot's finite context window. It's strongly recommended to break down tasks such as reading entire modules into smaller chunks. For a focused discussion, use review comments to chat about specific files and their changes, instead of using the PR comments.

CodeRabbit Commands (Invoked using PR comments)

  • @coderabbitai pause to pause the reviews on a PR.
  • @coderabbitai resume to resume the paused reviews.
  • @coderabbitai review to trigger an incremental review. This is useful when automatic reviews are disabled for the repository.
  • @coderabbitai full review to do a full review from scratch and review all the files again.
  • @coderabbitai summary to regenerate the summary of the PR.
  • @coderabbitai generate docstrings to generate docstrings for this PR. (Beta)
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai configuration to show the current CodeRabbit configuration for the repository.
  • @coderabbitai help to get help.

Other keywords and placeholders

  • Add @coderabbitai ignore anywhere in the PR description to prevent this PR from being reviewed.
  • Add @coderabbitai summary to generate the high-level summary at a specific location in the PR description.
  • Add @coderabbitai anywhere in the PR title to generate the title automatically.

CodeRabbit Configuration File (.coderabbit.yaml)

  • You can programmatically configure CodeRabbit by adding a .coderabbit.yaml file to the root of your repository.
  • Please see the configuration documentation for more information.
  • If your editor has YAML language server enabled, you can add the path at the top of this file to enable auto-completion and validation: # yaml-language-server: $schema=https://coderabbit.ai/integrations/schema.v2.json

Documentation and Community

  • Visit our Documentation for detailed information on how to use CodeRabbit.
  • Join our Discord Community to get help, request features, and share feedback.
  • Follow us on X/Twitter for updates and announcements.

@github-actions
Copy link
Copy Markdown

github-actions Bot commented Jan 8, 2025

Coverage Report

Status Category Percentage Covered / Total
🔵 Lines 71.02% 5417 / 7627
🔵 Statements 71.02% 5417 / 7627
🔵 Functions 68.45% 217 / 317
🔵 Branches 82.82% 704 / 850
File Coverage
File Stmts Branches Functions Lines Uncovered Lines
Changed Files
config/util.js 94.36% 80% 100% 94.36% 134-141
src/filters/filters.js 100% 100% 100% 100%
src/filters/schemaIssues.js 71.42% 50% 100% 71.42% 14-19
src/middleware/common.middleware.js 82.15% 92.17% 48.83% 82.15% 21-30, 34, 55-56, 68-70, 81, 97-104, 185-186, 198-204, 305, 314-316, 346-348, 386-394, 482-486, 491-494, 522-531, 589-590, 592-593, 595-596, 657-712
src/middleware/entryIssueDetails.middleware.js 88.59% 88.23% 57.14% 88.59% 22-24, 47-53, 60-66
src/middleware/middleware.builders.js 87.26% 88.57% 83.33% 87.26% 38, 107-118, 131-144, 261-264, 285-293
src/routes/guidance.js 0% 0% 0% 0% 1-11
src/routes/schemas.js 100% 100% 100% 100%
src/serverSetup/errorHandlers.js 0% 0% 0% 0% 1-51
src/serverSetup/middlewares.js 0% 0% 0% 0% 1-44
src/services/asyncRequestApi.js 100% 77.77% 100% 100%
src/services/datasette.js 100% 100% 100% 100%
src/utils/errors.js 93.54% 40% 100% 93.54% 26-27
Generated in workflow #574 for commit 4eea2ef by the Vitest Coverage Report Action

Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
config/util.js (1)

Line range hint 130-143: Consider enhancing error handling for production environments

Given that the PR objectives mention different error handling for production vs non-production environments, consider adding environment-specific validation logic.

 export const validateConfig = (config) => {
   try {
     return v.parse(ConfigSchema, config)
   } catch (error) {
+    const isProd = process.env.NODE_ENV === 'production' || 
+                   process.env.ENVIRONMENT === 'production'
+    
     console.error('invalid config', error.message)
     for (const issue of error.issues) {
-      console.info(
+      console[isProd ? 'error' : 'info'](
         `issue under path: [${issue.path.map((elem) => elem.key).join(', ')}]`
       )
     }
     throw error
   }
 }
📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 2e3c217 and 9760e44.

📒 Files selected for processing (1)
  • config/util.js (2 hunks)
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests / test
🔇 Additional comments (2)
config/util.js (2)

97-102: Well-structured contact configuration schema!

The implementation includes proper email validation and follows the established pattern of nested configuration objects. The trailing comma improves maintainability for future additions.


123-129: Well-documented validation function with proper type inference!

The JSDoc documentation and error handling implementation are thorough and maintainable.

@eveleighoj eveleighoj temporarily deployed to submit-pr-768 January 10, 2025 16:46 Inactive
Copy link
Copy Markdown
Contributor

@coderabbitai coderabbitai Bot left a comment

Choose a reason for hiding this comment

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

Actionable comments posted: 0

🧹 Nitpick comments (1)
test/unit/middleware/entryIssueDetails.middleware.test.js (1)

131-131: LGTM! Enhanced error message clarity.

The updated error messages now provide more specific context about missing values, which aligns well with the PR's objective of improving error handling.

Consider adding test cases for scenarios where both issues and resources are missing to ensure complete coverage of error states.

Also applies to: 152-152

📜 Review details

Configuration used: CodeRabbit UI
Review profile: CHILL
Plan: Pro

📥 Commits

Reviewing files that changed from the base of the PR and between 8c63fd2 and 4eea2ef.

📒 Files selected for processing (3)
  • src/middleware/common.middleware.js (3 hunks)
  • test/unit/middleware/entryIssueDetails.middleware.test.js (2 hunks)
  • test/unit/views/organisations/lpaOverviewPage.test.js (1 hunks)
🧰 Additional context used
📓 Learnings (1)
test/unit/views/organisations/lpaOverviewPage.test.js (1)
Learnt from: GeorgeGoodall-GovUk
PR: digital-land/submit#510
File: test/unit/views/organisations/dataset-overview.test.js:3-3
Timestamp: 2024-11-12T10:13:49.419Z
Learning: Ensure to verify import paths in all relevant test files before flagging inconsistencies.
⏰ Context from checks skipped due to timeout of 90000ms (1)
  • GitHub Check: run-tests / test
🔇 Additional comments (4)
test/unit/views/organisations/lpaOverviewPage.test.js (1)

70-70: LGTM! Improved dataset validation.

The enhanced checks for both existence and length of datasets provide better protection against edge cases with empty arrays.

Also applies to: 76-76

src/middleware/common.middleware.js (3)

9-9: LGTM! Added error handling utilities.

The import of error handling utilities aligns with the PR's objective of standardising error handling.


101-102: LGTM! Enhanced error handling in query validation.

The use of MiddlewareError with status code and context provides a more structured approach to handling validation errors.


131-131: LGTM! Standardised 404 error handling.

The change to use MiddlewareError for page range errors maintains consistency with the new error handling approach.

Copy link
Copy Markdown
Contributor

@GeorgeGoodall-GovUk GeorgeGoodall-GovUk left a comment

Choose a reason for hiding this comment

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

awesome! this is going to be super useful

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Tech Debt: display technical errors on the error page as they occur in staging and development

3 participants