Skip to content

Commit

Permalink
Merge pull request #39 from randovania/feature/improve-error-msg
Browse files Browse the repository at this point in the history
Improve error message for add_new_asset
  • Loading branch information
henriquegemignani authored Jul 20, 2023
2 parents 6113428 + b48385e commit a8ebbe4
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 2 deletions.
10 changes: 8 additions & 2 deletions src/mercury_engine_data_structures/file_tree_editor.py
Original file line number Diff line number Diff line change
Expand Up @@ -216,11 +216,17 @@ def get_parsed_asset(self, name: str, *, in_pkg: Optional[str] = None,
def add_new_asset(self, name: str, new_data: typing.Union[bytes, BaseResource],
in_pkgs: typing.Iterable[str]):
"""
Adds an asset that doesn't already exists.
Adds an asset that doesn't already exist.
"""
asset_id = resolve_asset_id(name, self.target_game)
if self.does_asset_exists(asset_id):
raise ValueError(f"{name} already exists")
if asset_id in self._modified_resources:
raise ValueError(f"{name} was already modified")
else:
raise ValueError("Asset already exists in:\n" + "\n".join(
pkg if pkg is not None else "In the RomFS"
for pkg in self._files_for_asset_id[asset_id]
))

in_pkgs = list(in_pkgs)
files_set = set()
Expand Down
13 changes: 13 additions & 0 deletions tests/test_file_tree_editor.py
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
import re

import pytest


def test_add_new_file_exists_romfs(dread_file_tree):
with pytest.raises(ValueError, match=re.escape("Asset already exists in:\nIn the RomFS")):
dread_file_tree.add_new_asset("config.ini", b"boo", [])


def test_add_new_file_exists_pkg(dread_file_tree):
with pytest.raises(ValueError, match=re.escape("Asset already exists in:\npacks/maps/s010_cave/s010_cave.pkg")):
dread_file_tree.add_new_asset("maps/levels/c10_samus/s010_cave/s010_cave.brfld", b"boo", [])

0 comments on commit a8ebbe4

Please sign in to comment.