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

[Bug] Search command errors if JSON file has array as root element #6239

Open
akarel-mb opened this issue Dec 3, 2024 · 1 comment
Open
Labels

Comments

@akarel-mb
Copy link

Bug Report

Current Behavior

In the event that a bucket is added that includes JSON files with an Array as the root element the scoop search command will throw an error for every offending file.

Expected Behavior

JSON files with arrays as root elements will be skipped

Additional context/output

MethodInvocationException: C:\...\scoop\apps\scoop\current\libexec\scoop-search.ps1:38
Line |
  38 |      if (!$json.RootElement.TryGetProperty('bin', [ref] $bin)) { retur …
     |          ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
     | Exception calling "TryGetProperty" with "2" argument(s): "The requested operation requires an element of type 'Object', but the target element
     | has type 'Array'."

Possible Solution

Adding the following on the first line of the bin_match_json method in scoop-search.ps1 will skip JSON files with arrays as root elements.

if ($json.RootElement.ValueKind -eq [System.Text.Json.JsonValueKind]::Array) { return $false }

System details

Windows version: 11

OS architecture: 64bit

PowerShell version: 7.4.6

Scoop Configuration

{
  "last_update": "2024-12-03T10:55:10.7777953-05:00",
  "scoop_branch": "master",
  "scoop_repo": "https://github.com/ScoopInstaller/Scoop"
}
@akarel-mb akarel-mb added the bug label Dec 3, 2024
@akarel-mb
Copy link
Author

akarel-mb commented Dec 3, 2024

Might make sense to add a more robust JSON validation method to catch similar issues like #6149

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

1 participant