Skip to content

Commit 45e792a

Browse files
committed
fix: manifest file path not shown if parsing failed
1 parent 4096a48 commit 45e792a

3 files changed

Lines changed: 48 additions & 16 deletions

File tree

bootstrap.ps1

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55

66
function Invoke-Bootstrap {
77
# Download bootstrap scripts from external repository
8-
Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.14.2/install.ps1 | Invoke-Expression
8+
Invoke-RestMethod https://raw.githubusercontent.com/avengineers/bootstrap-installer/v1.17.0/install.ps1 | Invoke-Expression
99
# Execute bootstrap script
1010
. .\.bootstrap\bootstrap.ps1
1111
}

src/py_app_dev/core/scoop_wrapper.py

Lines changed: 19 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -203,21 +203,25 @@ def parse_env_vars(env_set: Dict[str, str], app_path: Path) -> Dict[str, Any]:
203203
def parse_manifest_file(self, manifest_file: Path) -> InstalledScoopApp:
204204
app_directory: Path = manifest_file.parent
205205
tool_name: str = app_directory.parent.name
206-
with open(manifest_file) as f:
207-
manifest_data: Dict[str, Any] = json.load(f)
208-
tool_version: str = manifest_data.get("version", "")
209-
bin_dirs: List[Path] = self.parse_bin_dirs(manifest_data.get("bin", []))
210-
env_add_path: List[Path] = self.parse_env_path_dirs(manifest_data.get("env_add_path", []))
211-
installed_app = InstalledScoopApp(
212-
name=tool_name,
213-
version=tool_version,
214-
path=app_directory,
215-
manifest_file=manifest_file,
216-
bin_dirs=bin_dirs,
217-
env_add_path=env_add_path,
218-
env_vars=self.parse_env_vars(manifest_data.get("env_set", {}), app_directory),
219-
)
220-
return installed_app
206+
try:
207+
with open(manifest_file) as f:
208+
manifest_data: Dict[str, Any] = json.load(f)
209+
except json.JSONDecodeError as e:
210+
raise UserNotificationException(f"Failed to parse manifest file: {manifest_file.as_posix()}. Error: {e}") from None
211+
212+
tool_version: str = manifest_data.get("version", "")
213+
bin_dirs: List[Path] = self.parse_bin_dirs(manifest_data.get("bin", []))
214+
env_add_path: List[Path] = self.parse_env_path_dirs(manifest_data.get("env_add_path", []))
215+
installed_app = InstalledScoopApp(
216+
name=tool_name,
217+
version=tool_version,
218+
path=app_directory,
219+
manifest_file=manifest_file,
220+
bin_dirs=bin_dirs,
221+
env_add_path=env_add_path,
222+
env_vars=self.parse_env_vars(manifest_data.get("env_set", {}), app_directory),
223+
)
224+
return installed_app
221225

222226
def get_installed_apps(self) -> List[InstalledScoopApp]:
223227
installed_tools: List[InstalledScoopApp] = []

tests/test_scoop_wrapper.py

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -525,3 +525,31 @@ def test_bin_dirs_with_root_executable(scoop_dir: Path) -> None:
525525

526526
# Assert the bin_dirs includes the app root directory
527527
assert installed_app.bin_dirs == [Path(".")], "The app root directory should be included in bin_dirs for root-level executables."
528+
529+
530+
def test_parse_manifest_file_invalid_json(scoop_dir: Path) -> None:
531+
"""Test that parse_manifest_file raises UserNotificationException for invalid JSON."""
532+
scoop_wrapper = create_scoop_wrapper(scoop_dir / "scoop.ps1")
533+
534+
# Create a mock manifest file with invalid JSON
535+
manifest_file = scoop_dir / "apps" / "app_with_invalid_json" / "1.0" / "manifest.json"
536+
manifest_file.parent.mkdir(parents=True)
537+
manifest_file.write_text("{ invalid json }")
538+
539+
# Assert that UserNotificationException is raised with the correct message
540+
with pytest.raises(UserNotificationException, match=f"Failed to parse manifest file: {manifest_file.as_posix()}.*"):
541+
scoop_wrapper.parse_manifest_file(manifest_file)
542+
543+
544+
def test_parse_manifest_file_invalid_characters(scoop_dir: Path) -> None:
545+
"""Test that parse_manifest_file raises UserNotificationException for invalid characters."""
546+
scoop_wrapper = create_scoop_wrapper(scoop_dir / "scoop.ps1")
547+
548+
# Create a mock manifest file with invalid characters
549+
manifest_file = scoop_dir / "apps" / "app_with_invalid_chars" / "1.0" / "manifest.json"
550+
manifest_file.parent.mkdir(parents=True)
551+
manifest_file.write_text('\x00\x01\x02{"abc":"val"}') # Invalid characters
552+
553+
# Assert that UserNotificationException is raised with the correct message
554+
with pytest.raises(UserNotificationException, match=rf"Failed to parse manifest file: {manifest_file.as_posix()}.*"):
555+
scoop_wrapper.parse_manifest_file(manifest_file)

0 commit comments

Comments
 (0)