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

[PLA-2055] Fix CreateFuelTankMutation on no dispatchRule #75

Merged
merged 2 commits into from
Dec 4, 2024

Conversation

leonardocustodio
Copy link
Contributor

@leonardocustodio leonardocustodio commented Dec 4, 2024

PR Type

Bug fix


Description

  • Fixed a potential error in the addPermittedExtrinsics method of CreateFuelTankMutation by adding a check to ensure dispatchRules is not empty before accessing its first element.
  • Improved error handling to prevent null reference issues.

Changes walkthrough 📝

Relevant files
Bug fix
CreateFuelTankMutation.php
Fix potential error when `dispatchRules` is empty               

src/GraphQL/Mutations/CreateFuelTankMutation.php

  • Added a check to ensure dispatchRules is not empty before accessing
    its first element.
  • Prevented potential errors when dispatchRules is empty.
  • +1/-1     

    💡 PR-Agent usage: Comment /help "your question" on any pull request to receive relevant information

    Signed-off-by: Leonardo Custodio <leonardo@enjin.io>
    @leonardocustodio leonardocustodio changed the title Update CreateFuelTankMutation.php [PLA-2055] Fix CreateFuelTankMutation on no dispatchRule Dec 4, 2024
    @leonardocustodio leonardocustodio self-assigned this Dec 4, 2024
    Copy link

    github-actions bot commented Dec 4, 2024

    PR Reviewer Guide 🔍

    Here are some key observations to aid the review process:

    ⏱️ Estimated effort to review: 2 🔵🔵⚪⚪⚪
    🧪 No relevant tests
    🔒 No security concerns identified
    ⚡ Recommended focus areas for review

    Error Handling
    The added check for empty dispatchRules or null permittedExtrinsics might not handle all edge cases. Consider adding more comprehensive checks or handling for other potential null or unexpected values within dispatchRules.

    Copy link

    github-actions bot commented Dec 4, 2024

    PR Code Suggestions ✨

    Explore these optional code suggestions:

    CategorySuggestion                                                                                                                                    Score
    Possible issue
    Prevent errors by ensuring the first element of $dispatchRules is an object with the necessary properties before accessing it

    Check if $dispatchRules is not only non-empty but also contains an object with a
    defined permittedExtrinsics property before accessing it. This prevents potential
    errors when $dispatchRules is empty or the first element is not an object or lacks
    the permittedExtrinsics property.

    src/GraphQL/Mutations/CreateFuelTankMutation.php [131-132]

    -if (empty($dispatchRules) || $dispatchRules[0]->permittedExtrinsics === null) {
    +if (empty($dispatchRules) || !is_object($dispatchRules[0]) || $dispatchRules[0]->permittedExtrinsics === null) {
         return $encodedData;
     }
    Suggestion importance[1-10]: 8

    Why: The suggestion improves the robustness of the code by checking if the first element of $dispatchRules is an object before accessing its properties. This prevents runtime errors in cases where $dispatchRules might not contain an object or the object does not have the permittedExtrinsics property.

    8

    @leonardocustodio leonardocustodio merged commit 40b742c into master Dec 4, 2024
    5 of 7 checks passed
    @leonardocustodio leonardocustodio deleted the leonardocustodio-patch-1 branch December 4, 2024 14:16
    Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
    Development

    Successfully merging this pull request may close these issues.

    2 participants