Skip to content

Conversation

seanbudd
Copy link
Member

@seanbudd seanbudd commented Mar 26, 2025

When exceptions are raised in submission, the exception itself is reported to the submitter, not the manifest._errors contents.

This creates a less helpful comment e.g.:
nvaccess/addon-datastore#5198 (comment)

Tested by running createJson.py locally

Also updated dependencies

Summary by CodeRabbit

  • Refactor
    • Improved error handling to ensure more consistent and clear error messages during data processing.
  • Chore
    • Updated key dependencies to incorporate the latest stability and performance improvements, including configobj and jsonschema.

@seanbudd seanbudd requested a review from SaschaCowley March 26, 2025 00:40
Copy link

coderabbitai bot commented Mar 26, 2025

Walkthrough

The pull request refines error handling in the _createDictMatchingJsonSchema function by replacing custom error message assignments on the manifest object with direct raising of standard exceptions. Additionally, it updates dependency versions in requirements.txt by changing the commit hash for configobj and upgrading jsonschema from version 3.1 to 4.23.0. These changes streamline error reporting and ensure the project uses updated dependency versions.

Changes

File(s) Change Summary
_validate/createJson.py Updated error handling in _createDictMatchingJsonSchema: now directly raises ValueError and KeyError instead of assigning custom error messages to manifest._errors.
requirements.txt Updated dependencies: changed configobj commit hash from 3e2f4cc to 8be54629ee7c26acb5c865b74c76284e80f3aa31 and upgraded jsonschema from 3.1 to 4.23.0.

Sequence Diagram(s)

sequenceDiagram
    participant Caller
    participant Validator
    Caller->>Validator: Call _createDictMatchingJsonSchema(manifest)
    alt Manifest Version Parsing Error
        Validator-->>Caller: Raise ValueError("Manifest version invalid ...")
    else Missing Required Key
        Validator-->>Caller: Raise KeyError("Manifest missing required key 'keyName'")
    else Successful Processing
        Validator-->>Caller: Return processed dictionary
    end
Loading

Poem

Hopping through the code with glee,
I saw errors set free and clean as can be.
No more quiet messages hidden behind,
Direct exceptions now clearly defined.
As a rabbit, I cheer with a twitch and a hop,
Celebrating clarity in every code drop!


📜 Recent review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 67b3ba0 and 2ef5b1d.

📒 Files selected for processing (1)
  • _validate/createJson.py (4 hunks)
🚧 Files skipped from review as they are similar to previous changes (1)
  • _validate/createJson.py

🪧 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.
  • @coderabbitai resolve resolve all the CodeRabbit review comments.
  • @coderabbitai plan to trigger planning for file edits and PR creation.
  • @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.

Copy link

@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 (4)
_validate/createJson.py (4)

94-95: Improve exception handling by preserving the original exception context

The direct error raising approach is better than setting manifest._errors, but you should preserve the original exception context using raise ... from err syntax.

except ValueError as err:
-	raise ValueError(f"Manifest version invalid {addonVersionNumber}")
+	raise ValueError(f"Manifest version invalid {addonVersionNumber}") from err

This preserves the exception chain, making debugging easier while still providing the clear error message to users.

🧰 Tools
🪛 Ruff (0.8.2)

95-95: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


117-118: Improve exception handling by preserving the original exception context

Similar to the previous case, preserve the KeyError's context for better debugging.

except KeyError as e:
-	raise KeyError(f"Manifest missing required key '{e.args[0]}'.")
+	raise KeyError(f"Manifest missing required key '{e.args[0]}'.") from e
🧰 Tools
🪛 Ruff (0.8.2)

118-118: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


140-141: Improve exception handling by preserving the original exception context

Preserve the exception context for translation-related errors as well.

except KeyError as e:
-	raise KeyError(f"Translation for {langCode} missing required key '{e.args[0]}'.")
+	raise KeyError(f"Translation for {langCode} missing required key '{e.args[0]}'.") from e
🧰 Tools
🪛 Ruff (0.8.2)

141-141: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


233-243: Consider updating the main error handling section to maintain consistency

The main error handling block in the main() function still checks manifest.errors first. For consistency with your changes in _createDictMatchingJsonSchema, consider updating this section to prioritize the exception message when manifest.errors is empty.

except Exception as e:
	if manifest.errors:
		if errorFilePath:
			with open(errorFilePath, "w") as errorFile:
				errorFile.write(f"Validation Errors:\n{manifest.errors}")
		raise ValueError(f"Invalid manifest file: {manifest.errors}")
	else:
		if errorFilePath:
			with open(errorFilePath, "w") as errorFile:
-				errorFile.write(f"Validation Errors:\n{e}")
+				# Use the exception message which now contains the detailed error information
+				errorFile.write(f"Validation Errors:\n{str(e)}")
		raise

This change ensures that the detailed error messages you've added in the exception raising are properly forwarded to the error output file.

🧰 Tools
🪛 Ruff (0.8.2)

238-238: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between 75e7a0c and 67b3ba0.

📒 Files selected for processing (2)
  • _validate/createJson.py (4 hunks)
  • requirements.txt (1 hunks)
🧰 Additional context used
🪛 Ruff (0.8.2)
_validate/createJson.py

95-95: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


118-118: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


141-141: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

🔇 Additional comments (3)
requirements.txt (1)

8-9:

❓ Verification inconclusive

Significant dependency updates should be verified for compatibility

The PR updates two dependencies:

  1. configobj to a specific commit (8be54629ee)
  2. jsonschema from 3.1 to 4.23.0 (a major version jump)

These updates align with the error handling improvements, but the major version upgrade for jsonschema could potentially introduce breaking changes.

Please verify that these updates are compatible with the rest of the codebase, particularly with how schema validation is performed. Consider running the test suite to ensure no regressions are introduced.


🏁 Script executed:

#!/bin/bash
# Check for any compatibility issues with jsonschema 4.23.0
pip install jsonschema==4.23.0 --dry-run
# Find any files that import jsonschema to understand potential impact
rg "import jsonschema" --type py

Length of output: 937


Verify compatibility for critical dependency updates

The PR updates two dependencies:

  • configobj: Updated to a specific commit (8be54629ee7c26acb5c865b74c76284e80f3aa31), likely incorporating important fixes or improvements.
  • jsonschema: Upgraded from version 3.1 to 4.23.0—a major version jump that can introduce breaking changes.

The dry-run installation for jsonschema 4.23.0 completed without errors, indicating it’s correctly installed. However, the search for import jsonschema did not return any output, which raises some uncertainty regarding its direct usage in the codebase. It’s possible that jsonschema is used indirectly or in a non-obvious manner.

I recommend:

  • Manually verifying any code using jsonschema—for example, checking how schema validation is performed (possibly in files like createJson.py or elsewhere).
  • Running the full test suite to ensure that the major version upgrade doesn’t introduce regressions or compatibility issues.
_validate/createJson.py (2)

3-3: Copyright year updated appropriately

The copyright year has been extended to include 2025, which is a good practice for maintaining up-to-date copyright notices.


90-143: Approve improved error handling approach

The changes to directly raise exceptions with meaningful messages rather than setting manifest._errors is a significant improvement to error reporting. This ensures that add-on submitters receive clear, specific error messages that help them understand and fix issues with their submissions.

This implementation aligns perfectly with the PR objective to "ensure that the relevant error details from manifest._errors are communicated to the submitter, thereby improving the clarity and usefulness of the feedback provided during the submission process."

🧰 Tools
🪛 Ruff (0.8.2)

95-95: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


118-118: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)


131-131: Loop control variable manifest overrides iterable it iterates

(B020)


141-141: Within an except clause, raise exceptions with raise ... from err or raise ... from None to distinguish them from errors in exception handling

(B904)

@SaschaCowley
Copy link
Member

I agree with the bot's suggestion to use raise ... from ...

@seanbudd seanbudd merged commit 6a7f056 into main Mar 26, 2025
2 checks passed
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.

2 participants