-
Notifications
You must be signed in to change notification settings - Fork 80
fix(pip native inspector): Prevent NPE when no project name can be derived IDETECT-4923 #1621
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
Changes from all commits
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
| Original file line number | Diff line number | Diff line change | ||||
|---|---|---|---|---|---|---|
|
|
@@ -122,18 +122,30 @@ private String getProjectName(File directory, ExecutableTarget pythonExe, File s | |||||
|
|
||||||
| String projectName = providedProjectName; | ||||||
|
|
||||||
| if (tomlParseResult != null) { | ||||||
| TomlTable projectTable = tomlParseResult.getTable(PROJECT_KEY); | ||||||
| if(projectTable.contains(NAME_KEY)) { | ||||||
| projectName = projectTable.getString(NAME_KEY); | ||||||
| try { | ||||||
| if (tomlParseResult != null && (tomlParseResult.getTable(PROJECT_KEY) != null)) { | ||||||
| TomlTable projectTable = tomlParseResult.getTable(PROJECT_KEY); | ||||||
| if (projectTable != null && projectTable.contains(NAME_KEY)) { | ||||||
| projectName = projectTable.getString(NAME_KEY); | ||||||
| return projectName; | ||||||
| } | ||||||
| } | ||||||
| } else if (setupFile != null && setupFile.exists()) { | ||||||
| List<String> pythonArguments = Arrays.asList(setupFile.getAbsolutePath(), "--name"); | ||||||
| ExecutableOutput executableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pythonExe, pythonArguments)); | ||||||
| if (executableOutput.getReturnCode() == 0) { | ||||||
| List<String> output = executableOutput.getStandardOutputAsList(); | ||||||
| projectName = output.get(output.size() - 1).replace('_', '-').trim(); | ||||||
| } catch (Exception e) { | ||||||
| logger.debug("Failed to parse project name from pyproject.toml."); | ||||||
|
Comment on lines
+133
to
+134
|
||||||
| } | ||||||
|
|
||||||
|
|
||||||
| try { | ||||||
| if (setupFile != null && setupFile.exists()) { | ||||||
| List<String> pythonArguments = Arrays.asList(setupFile.getAbsolutePath(), "--name"); | ||||||
| ExecutableOutput executableOutput = executableRunner.execute(ExecutableUtils.createFromTarget(directory, pythonExe, pythonArguments)); | ||||||
| if (executableOutput.getReturnCode() == 0) { | ||||||
| List<String> output = executableOutput.getStandardOutputAsList(); | ||||||
| projectName = output.get(output.size() - 1).replace('_', '-').trim(); | ||||||
| } | ||||||
| } | ||||||
| } catch (Exception e) { | ||||||
|
||||||
| } catch (Exception e) { | |
| } catch (ExecutableRunnerException e) { |
Copilot
AI
Jan 6, 2026
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The error message should include the exception details to aid debugging. Consider logging the exception message or using logger.debug with the exception parameter: logger.debug(\"Failed to parse project name from setup.py.\", e)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Catching generic
Exceptionis overly broad. Consider catching more specific exception types (e.g.,NullPointerException,TomlParseException) to avoid masking unexpected errors that should be handled differently or propagated.