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

improve exception messages used within import dialog #314

Conversation

cosmicexplorer
Copy link
Contributor

  • Provide better exception messages when PantsUtil.listAllTargets() fails.
    • e.g. whether the process finished with an exit code or was interrupted
  • Log the exit code and output file if the process ran to completion.

Currently, the function throws a PantsException on failure which describes the command line that failed. This command line already contains the output file, incidentally, but this change makes the output file explicit.

Daniel McClanahan added 2 commits September 8, 2017 09:00
when .listAllTargets() fails:
- log the command line
- provide better exception messages for failure cases
@cosmicexplorer
Copy link
Contributor Author

CI failed because of the md5sum, just uploaded another commit to fix that. Since .listAllTargets() is called exactly once in an integration test, I want to add some unit tests that actually ensure these exceptions are thrown.

@cosmicexplorer cosmicexplorer changed the title improve exception messages used within import dialog improve exception messages used within import dialog [WIP] Sep 8, 2017
Copy link
Collaborator

@wisechengyi wisechengyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks! Look mostly good with some aspects to address.

processOutput.getExitCode()) +
String.format("argv: '%s'\n", cmd.getCommandLineString()) +
String.format("stdout:\n%s\n", listOutput) +
String.format("warnings:\n%s\n", processOutput.getStdout()) +
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if the command fails, nothing will be in listOutput.

so stdout will be processOutput.getStdout() and stderr will be processOutput.getStderr()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense -- I've made the exception message contain just stdout and stderr as you described.

String.format("argv: '%s'\n", cmd.getCommandLineString()) +
String.format("stdout:\n%s\n", listOutput) +
String.format("warnings:\n%s\n", processOutput.getStdout()) +
String.format("stderr:\n%s\n", processOutput.getStderr());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: instead of \n on every line, put them in an array then join with \n

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed.

}
else {
throw new PantsException("Failed:" + cmd.getCommandLineString());
final String errorDescription =
String.format("could not list targets: pants exited with status %d\n",
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit: capitalization Could not...... Pants ...

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Fixed, also fixed in the other exception message to "Could not execute command...".

String.format("could not execute command: '%s' due to error: '%s'",
cmd.getCommandLineString(),
e.getMessage());
LOG.warn(noProcessErrMsg, e);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

nit:
1.noProcessErrMsg may suggests boolean, maybe otherProcessErrMsg
2. capitalization in error message

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Changed to processCreationFailureMessage and fixed capitalization.

wisechengyi pushed a commit that referenced this pull request Oct 2, 2017
master currently fails the test suite, because jetbrains has removed the previous version of IDEA for download from their site. This pull request makes the changes listed below so master can run again. This issue was blocking #312 and #314.

- bump ij version to the [most recent available release](https://www.jetbrains.com/idea/download)
  - update list of jars read from the scala plugin directory for the new version of ij
- update checksums for IDEA and plugins
- update scala sdk version to 2.11.11
- explicitly specify python and jdk version in `.travis.yml`
- refactor some calls that were marked deprecated in between previous and current versions of ij
@cosmicexplorer
Copy link
Contributor Author

I removed .loadTargets() and added the build file path check to PantsUtil.listAllTargets(), which allowed me to test both the PantsUtil function as well as the UI action. This and the previous commit both pass CI.

I still don't know how to make a test checking whether the project import dialog does actually get closed after ./pants list ... fails. There may be some hook that runs when the dialog is dismissed, but I'm not sure. I think that's a lot of effort to do in this pull request, but I'll try to figure out ways to do that in the future.

@cosmicexplorer cosmicexplorer changed the title improve exception messages used within import dialog [WIP] improve exception messages used within import dialog Oct 3, 2017
Copy link
Collaborator

@wisechengyi wisechengyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

looks good. Thanks @cosmicexplorer ! just a few points

File projectDir = getProjectFolder();
VirtualFile virtualProjectDir = LocalFileSystem.getInstance().findFileByIoFile(projectDir);
Optional<VirtualFile> pantsIniFileResult = PantsUtil.findPantsIniFile(Optional.ofNullable(virtualProjectDir));
assertTrue(pantsIniFileResult.isPresent());
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Could you add appropriate error messages for all assertions?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, here and elsewhere.

File nonexistentFile = new File(nonexistentFilePath);
assertTrue(!nonexistentFile.exists());
assertTrue(!PantsUtil.isBUILDFilePath(nonexistentFilePath));
assertEquals(PantsUtil.listAllTargets(nonexistentFilePath),
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Generally speaking, each test function should focus on one method instead of covering all the methods. Otherwise if you change the behavior of some function in the future, it requires modifying multiple test functions. E.g.

void testBuildFilePath() {
assertTrue("msg", PantsUtil.isBUILDFilePath(...))
assertFalse("msg", PantsUtil.isBUILDFilePath(...))
}

void testListTargets() {
...
}

Let me know if you would prefer to do so with a separate patch.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

That makes sense. I'll fix that in this file and in PantsProjectSettingsTest.java.

String pantsIniFilePath = pantsIniFileResult.get().getPath();
File pantsIniFile = new File(pantsIniFilePath);
assertTrue(pantsIniFile.exists() && !pantsIniFile.isDirectory());
assertTrue(!PantsUtil.isBUILDFilePath(pantsIniFilePath));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

use assertFalse instead, ditto for other cases.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Done, here and elsewhere.


public void testListTargetInvalidBuildFile() {
String projectDir = getProjectFolder().getPath();
Path invalidBuildFilePath = Paths.get(
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Gotcha, I'll try to make this cleaner.

} catch (PantsException e) {
caught = true;
}
assertTrue("PantsException not thrown for invalid BUILD file", caught);
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks for the example, I hadn't thought of that. I'll make the change.

Copy link
Collaborator

@wisechengyi wisechengyi left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @cosmicexplorer . just one nit


try {
PantsUtil.listAllTargets(invalidBuildFilePath);
fail(String.format("%s should have been thrown"));
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

is there a particular exception to be caught? what is %s for?

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Whoops. I used String.format() following the example you gave in your previous comment, but forgot that means I need to check it. Just pushed a change fixing this.

@wisechengyi wisechengyi merged commit 2dc6913 into pantsbuild:master Oct 5, 2017
@cosmicexplorer cosmicexplorer mentioned this pull request Oct 5, 2017
wisechengyi pushed a commit that referenced this pull request Dec 6, 2017
# Notable Changes
- Compatibility with IntelliJ 2017.3. #319 
- Add .idea, .pants.d to git ignore. #307 
- Improve exception messages used within import dialog. #314, #321 
- Update release doc. #306
- Add a lint action to the plugin context menus and dropdown menu. #312 
- Fix a bug which would occur when displaying two projects at once. #320 
- Attach annotations for plugin selected JDK. #308
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants