-
-
Notifications
You must be signed in to change notification settings - Fork 20
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
Add error handling for media update when file is missing or invalid #35
base: master
Are you sure you want to change the base?
Conversation
WalkthroughThis change updates the Changes
Sequence Diagram(s)sequenceDiagram
participant C as Client
participant MMI as MediaManagerInput
participant Media as Media Entity
C->>MMI: Call setUp($item)
alt $item valid (array with non-empty 'file')
MMI->>Media: Retrieve Media instance using UUID
Media-->>MMI: Return Media instance
MMI->>Media: Update order_column
else $item invalid
MMI-->>C: Skip Media retrieval and order update
end
Possibly related PRs
Poem
✨ Finishing Touches
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? 🪧 TipsChatThere are 3 ways to chat with CodeRabbit:
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)
Other keywords and placeholders
CodeRabbit Configuration File (
|
There was a problem hiding this 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)
src/Form/MediaManagerInput.php (1)
199-205
: Good addition of validation checks to prevent errors with invalid media items.The conditional checks added here effectively prevent the
array_keys(): Argument #1 ($array) must be of type array, null given
error mentioned in the PR objectives. The code now properly validates that:
$item
is an array$item
has a 'file' key- The 'file' value is an array
- The 'file' array is not empty
Additionally, the nested check for
$media
existence before updating is a good defensive programming practice.Consider adding logging when the validation fails to aid in debugging future issues. For example:
if (is_array($item) && isset($item['file']) && is_array($item['file']) && !empty($item['file'])) { $media = Media::where('uuid', array_keys($item['file'])[0])->first(); if($media){ $media->update([ 'order_column'=> $counter ]); } +} else { + \Illuminate\Support\Facades\Log::debug('MediaManagerInput: Skipping invalid media item', [ + 'item' => $item + ]); }
In this fix I added error handling when I do drag n drop on the column but the image is empty/not uploaded which causes an error:
array_keys(): Argument #1 ($array) must be of type array, null given
The improvements I made were to add conditions such as:
so around line 192 in the MediaManagerInput.php file the complete code now is: