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

Raise on attempting to remove a not existing child #553

Merged
merged 7 commits into from
May 15, 2023

Conversation

FelonEkonom
Copy link
Member

@FelonEkonom FelonEkonom requested a review from mat-hek as a code owner May 10, 2023 15:53
@FelonEkonom FelonEkonom added the no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md label May 10, 2023
@FelonEkonom FelonEkonom changed the title Raise on try to remove not existing child Raise on attempting to remove a not existing child May 10, 2023
Comment on lines 506 to 507
|> List.delete(nil)
|> Enum.uniq()
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
|> List.delete(nil)
|> Enum.uniq()
|> Enum.uniq()
|> List.delete(nil)

|> Enum.uniq()

children_or_children_groups
|> Enum.find(&(&1 not in all_children_and_children_groups))
Copy link
Member

Choose a reason for hiding this comment

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

instead of searching through all children, we could just search in the ones that are to be removed

Copy link
Member Author

Choose a reason for hiding this comment

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

value refs in line 522 contains only references to the children that we have to remove, while variable children_or_children_groups might contain not only children refs, but child groups names as well, so I am not convinced if this change will make the code simpler

Copy link
Member

Choose a reason for hiding this comment

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

but we can easily get the groups when retrieving refs

Copy link
Member Author

Choose a reason for hiding this comment

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

I have moved part of code checking whether removed child exist to the another function, IMO this is cleaner then previous version

@FelonEkonom FelonEkonom requested a review from mat-hek May 12, 2023 09:29
Comment on lines 544 to 553
Enum.find(removed_children_or_groups, fn name ->
not Map.has_key?(state.children, name) and not MapSet.member?(children_groups, name)
end)
|> case do
nil ->
:ok

child_ref ->
raise Membrane.ParentError, """
Trying to remove child #{inspect(child_ref)}, while such a child or children group does not exist.
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
Enum.find(removed_children_or_groups, fn name ->
not Map.has_key?(state.children, name) and not MapSet.member?(children_groups, name)
end)
|> case do
nil ->
:ok
child_ref ->
raise Membrane.ParentError, """
Trying to remove child #{inspect(child_ref)}, while such a child or children group does not exist.
removed_children_or_groups
|> Enum.reject(fn name ->
Map.has_key?(state.children, name) or MapSet.member?(children_groups, name)
end)
|> case do
[] ->
:ok
children_refs ->
raise Membrane.ParentError, """
Trying to remove children #{Enum.map_join(", ", &inspect/1)}, while such children or children groups do not exist.

@FelonEkonom FelonEkonom enabled auto-merge (squash) May 15, 2023 12:04
@FelonEkonom FelonEkonom disabled auto-merge May 15, 2023 12:04
@FelonEkonom FelonEkonom merged commit 2456cd1 into master May 15, 2023
1 check passed
@FelonEkonom FelonEkonom deleted the ensure-removed-child-exists branch May 15, 2023 13:14
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
no-changelog This label has to be added if changes from the PR are not meant to be placed in the CHANGELOG.md
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

2 participants