Fixed Inaccurate 'No Result Found' Behavior and corrected package-lock.json#6
Fixed Inaccurate 'No Result Found' Behavior and corrected package-lock.json#6Pranay22077 wants to merge 1 commit into
Conversation
…k.json Signed-off-by: Pranay <pranaygadh_mc24b06_003@dtu.ac.in>
There was a problem hiding this comment.
Pull Request Overview
This PR fixes the "No Result Found" behavior by implementing more accurate filtering of search results and adds proper error handling. The key improvement is that results are now filtered to only include packages whose names actually contain the search term, preventing false "no results" messages.
Key Changes
- Added try-catch error handling in the
searchfunction to gracefully handle API failures - Implemented client-side filtering in
trovato show only relevant results matching the search term - Made the action handler async with proper error handling using
parseAsync
Tip: Customize your code reviews with copilot-instructions.md. Create the file or learn how to get started.
| spinner.succeed(`Search complete for ${param}`) // Use succeed on success | ||
| return JSON.parse(result) | ||
| } catch (error) { | ||
| spinner.fail(`Search failed for ${param}: ${error.message}`) // Use fail on error |
There was a problem hiding this comment.
The spinner.fail() is called but the function continues to return a value instead of re-throwing the error. This could mask API failures from the caller. Consider either re-throwing the error or documenting why silent failure with empty results is the intended behavior.
|
|
||
| // --- Refined Check --- | ||
| // Filter for results where the package name actually includes the search term | ||
| const relevantResults = objects && objects.filter(obj => |
There was a problem hiding this comment.
If objects is undefined or null (which can happen when search returns { objects: [] } on error), objects.filter will throw a TypeError. The conditional check objects && protects the filter call, but if objects is undefined, relevantResults will be undefined, not an empty array. This will cause the length check on line 60 to fail. Consider using objects?.filter() or (objects || []).filter() to ensure relevantResults is always an array.
| const relevantResults = objects && objects.filter(obj => | |
| const relevantResults = (objects || []).filter(obj => |
| await trova(name, options) // Await the async trova function | ||
| } else { | ||
| console.log(chalk.red('No search term provided')) | ||
| program.help(); // Show help if no argument provided |
There was a problem hiding this comment.
This condition block (lines 89-92) is unreachable. Commander.js enforces required arguments defined with .argument('<name>'), so the action handler will never be called if the name argument is missing. The framework will automatically display help and exit before reaching this code.
| console.log(chalk.red(`❌ No relevant results found for query: ${name}`)) | ||
| // Optional: Log if the original search returned *something*, but nothing relevant | ||
| if (objects && objects.length > 0) { | ||
| console.log(chalk.yellow(` (Note: The API returned ${objects.length} loosely related package(s).)`)); |
There was a problem hiding this comment.
Corrected spelling: 'package(s).)' should be 'package(s)).' - the period should come before the closing parenthesis.
| console.log(chalk.yellow(` (Note: The API returned ${objects.length} loosely related package(s).)`)); | |
| console.log(chalk.yellow(` (Note: The API returned ${objects.length} loosely related package(s)).`)); |
There was a problem hiding this comment.
@gafreax
Are the changes made fine?
If yes, request you to merge the PR
Thanks
|
Hi @gafreax Thanks |
|
Hi @Pranay22077, please fix the suggestion in the comments, then I will check again! |
The issue: Inaccurate "No Result Found" Behavior has been fixed

In the process, 3 vulnerabilities (2 low, 1 moderate) were found in src/package-lock.json which are also corrected
