Skip to content

Minor adjustment on error semantics and model business rules #42

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

Merged
merged 1 commit into from
Feb 4, 2025

Conversation

GabrielBarberini
Copy link
Collaborator

@GabrielBarberini GabrielBarberini commented Feb 2, 2025

  • improve error semantics on simulation route crash
  • make fins and nosecone mandatory parameters

Summary by CodeRabbit

  • Refactor
    • Improved simulation error messages to clarify issues with parameter coherence.
    • Updated rocket configuration to require complete component information.
  • Tests
    • Enhanced test coverage by adding fixtures for key rocket components.
    • Streamlined test setup by removing deprecated mock fixtures.
  • Chores
    • Expanded the development environment with additional testing dependencies.

Copy link
Contributor

coderabbitai bot commented Feb 2, 2025

Walkthrough

This pull request updates error messages in simulation methods across several controllers to indicate that parameters may be physically incoherent. The Rocket model is modified so that its nose and fins attributes are now required rather than optional. Additionally, new development dependencies (pytest and httpx) have been added, and test fixtures have been adjusted accordingly—with new fixtures added in one test file and redundant ones removed in another.

Changes

File(s) Summary
lib/controllers/{environment, flight, motor, rocket}.py Updated error messages in simulation methods to include context that parameters may contain physically incoherent data.
lib/models/rocket.py Changed the nose and fins attributes from optional to required, enforcing stricter data requirements.
requirements-dev.txt Added new development dependencies: pytest for testing and httpx for HTTP client functionality.
tests/test_routes/{conftest.py, test_rockets_route.py} Added new fixtures for NoseCone and Fins in conftest.py and removed these fixtures from test_rockets_route.py to reflect model changes.

Possibly related PRs

  • API Refactoring #20: Involved modifications to error handling in simulation methods, specifically in the simulate_flight method, aligning with the error message updates in this PR.

Suggested reviewers

  • aasitvora99
  • Gui-FernandesBR
  • Lucas-Prates
  • MateusStano

Poem

I'm a code-hopping bunny, bouncing through each file,
Tweaking error messages with a clever, witty smile.
Rockets now have noses and fins so true,
Dependencies and tests get a shiny, fresh debut.
In a maze of code, I nibble joyfully all the while!
🥕🐰 Happy coding, hop on in style!

✨ 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.

Copy link
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 (4)
lib/controllers/environment.py (1)

267-267: LGTM! Error message improvement enhances debugging.

The updated error message now provides clearer context about simulation failures by indicating that parameters may not be physically coherent. This aligns well with the PR's objective to improve error semantics.

Consider adding a link to documentation about physical coherence requirements in the error message:

-                detail=f"Failed to simulate environment, parameters may contain data that is not physically coherent: {exc_str}",
+                detail=f"Failed to simulate environment, parameters may contain data that is not physically coherent (see https://docs.rocketpy.org/parameters): {exc_str}",
lib/controllers/rocket.py (1)

282-282: LGTM! Consistent error message improvement.

The error message update maintains consistency with other controllers while providing clearer context about simulation failures.

For consistency with the environment controller, consider adding the same documentation link:

-                detail=f"Failed to simulate rocket, parameters may contain data that is not physically coherent: {exc_str}",
+                detail=f"Failed to simulate rocket, parameters may contain data that is not physically coherent (see https://docs.rocketpy.org/parameters): {exc_str}",
tests/test_routes/conftest.py (2)

83-94: LGTM! Consider adding docstring.

The stub_nose_cone fixture provides a minimal valid NoseCone instance for testing.

Add a docstring to document the fixture's purpose and usage:

 @pytest.fixture
 def stub_nose_cone():
+    """Provides a minimal valid NoseCone instance for testing.
+    
+    Returns:
+        dict: JSON representation of a NoseCone instance
+    """
     nose_cone = NoseCone(

96-108: LGTM! Consider adding docstring.

The stub_fins fixture provides a minimal valid Fins instance for testing.

Add a docstring to document the fixture's purpose and usage:

 @pytest.fixture
 def stub_fins():
+    """Provides a minimal valid Fins instance for testing.
+    
+    Returns:
+        dict: JSON representation of a Fins instance
+    """
     fins = Fins(
📜 Review details

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

📥 Commits

Reviewing files that changed from the base of the PR and between a03a578 and ece22c0.

📒 Files selected for processing (8)
  • lib/controllers/environment.py (1 hunks)
  • lib/controllers/flight.py (1 hunks)
  • lib/controllers/motor.py (1 hunks)
  • lib/controllers/rocket.py (1 hunks)
  • lib/models/rocket.py (1 hunks)
  • requirements-dev.txt (1 hunks)
  • tests/test_routes/conftest.py (3 hunks)
  • tests/test_routes/test_rockets_route.py (0 hunks)
💤 Files with no reviewable changes (1)
  • tests/test_routes/test_rockets_route.py
✅ Files skipped from review due to trivial changes (2)
  • lib/controllers/flight.py
  • lib/controllers/motor.py
🧰 Additional context used
📓 Learnings (1)
tests/test_routes/conftest.py (1)
Learnt from: GabrielBarberini
PR: RocketPy-Team/Infinity-API#41
File: tests/test_routes/test_flights_route.py:122-125
Timestamp: 2024-12-07T11:50:08.415Z
Learning: In the project's pytest test files (e.g., `tests/test_routes/test_flights_route.py`), fixtures like `stub_rocket` and `stub_flight` are function-scoped and can be safely modified within tests without causing side effects.
🔇 Additional comments (4)
lib/models/rocket.py (1)

36-37: LGTM! Note: Breaking change detected.

Making nose and fins required parameters aligns with the PR objectives to modify model business rules. This change improves type safety by ensuring these critical components are always specified.

However, this is a breaking change that will require updates to all code creating Rocket instances.

Please ensure that:

  1. The package version is bumped according to semver
  2. The breaking changes are documented in the changelog
  3. All Rocket instance creations are updated across the codebase

Run this script to find potential instances requiring updates:

tests/test_routes/conftest.py (2)

7-7: LGTM!

The new imports align with the changes in the Rocket model requiring Fins and NoseCone.


111-123: LGTM! The fixture correctly uses the new required parameters.

The stub_rocket fixture has been properly updated to include the now-required nose and fins parameters using the new fixtures.

requirements-dev.txt (1)

4-5: LGTM! Development dependencies added.

The addition of pytest and httpx as development dependencies is appropriate:

  • pytest is required for the test fixtures
  • httpx is useful for testing HTTP endpoints

Run this script to check for version constraints and potential conflicts:

✅ Verification successful

Development dependencies verified
The output confirms that both pytest and httpx are correctly defined with no version conflicts. The dry run installation and version checks indicate that pytest (8.3.4) and httpx (0.28.1) match the expected latest versions with their dependency constraints properly satisfied.

🏁 Scripts executed

The following scripts were executed for the analysis:

Script:

#!/bin/bash
# Description: Check package versions and potential conflicts

# Install packages and check for conflicts
pip install pytest httpx --dry-run

# Get latest versions for comparison
echo "Latest versions:"
pip index versions pytest
pip index versions httpx

Length of output: 3857

Copy link
Member

Choose a reason for hiding this comment

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

Any reason for not allowing rockets without fins or nose?

Copy link
Collaborator Author

@GabrielBarberini GabrielBarberini Feb 2, 2025

Choose a reason for hiding this comment

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

Its a FUP from the recent debug session we had. We understand that rockets without fins or nose are a minor use-case but a major bug raiser. Since changing from mandatory to optional or vice-versa is an easy task we decided to keep it more restrictive for now.

The bug itself we were tracking is not on the API side tho. @phmbressan will probably share more details about this in the upcoming libdev meetings.

@GabrielBarberini GabrielBarberini merged commit e70e666 into master Feb 4, 2025
3 checks passed
@GabrielBarberini GabrielBarberini deleted the improve_simulation_error_semantics branch February 4, 2025 17:57
@coderabbitai coderabbitai bot mentioned this pull request Mar 8, 2025
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.

3 participants