Merge IJ-MR-13732 from balakhnin/beautify-error-output

GitOrigin-RevId: 3aa889b443a704382edc079f1115c5e7da688b59
This commit is contained in:
Sergey Balakhnin
2021-09-08 09:51:06 +00:00
committed by intellij-monorepo-bot
2 changed files with 33 additions and 22 deletions

View File

@@ -97,11 +97,16 @@ inspection.capitalized.done=Done.
inspection.application.file.cannot.be.found=File {0} cannot be found
inspection.application.opening.project=Opening project...
inspection.application.initializing.project=Initializing project...
inspection.application.unable.open.project=Unable to open project
inspection.application.directory.cannot.be.found=Directory {0} cannot be found
inspection.application.project.has.older.format.and.will.be.converted=Project has an older format and will be converted.
inspection.application.project.was.successfully.converted.old.project.files.were.saved.to.0=Project was converted successfully. Old project files were saved to {0}
inspection.application.cannot.convert.project.0=Cannot convert project: {0}
inspection.application.cannot.convert.the.project.the.following.files.are.read.only.0=Cannot convert the project. The following files are read only: {0}
inspection.application.cannot.initialize.vcs.mapping=Cannot initialize vcs mapping
inspection.application.cannot.configure.project.to.run.inspections=Cannot configure project to run inspections
inspection.application.profile.was.not.found.by.name.0.1=Profile with configured name ({0}) was not found (neither in project nor in config directory). Configured by: {1}
inspection.application.profile.failed.configure.by.path.0.1=Failed to load profile from ({0}). Configured by: {1}
# suppress inspection "UnusedProperty"
inspection.comparing.references.use.quickfix=Use equals()

View File

@@ -69,6 +69,8 @@ import org.jetbrains.concurrency.AsyncPromise;
import javax.xml.stream.XMLStreamException;
import java.io.File;
import java.io.IOException;
import java.io.PrintWriter;
import java.io.StringWriter;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.util.*;
@@ -122,7 +124,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
}
catch (Throwable e) {
LOG.error(e);
reportError(e.getMessage());
reportError(e);
gracefulExit();
return;
}
@@ -228,8 +230,10 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
reportMessageNoLineBreak(1, InspectionsBundle.message("inspection.application.opening.project"));
ConversionService conversionService = ConversionService.getInstance();
if (conversionService != null && conversionService.convertSilently(projectPath, createConversionListener()).openingIsCanceled()) {
gracefulExit();
StringBuilder convertErrorBuffer = new StringBuilder();
if (conversionService != null &&
conversionService.convertSilently(projectPath, createConversionListener(convertErrorBuffer)).openingIsCanceled()) {
onFailure(convertErrorBuffer.toString());
return null;
}
@@ -256,8 +260,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
);
Project project = projectRef.get();
if (project == null) {
reportError("Unable to open project");
gracefulExit();
onFailure(InspectionsBundle.message("inspection.application.unable.open.project"));
return null;
}
waitAllStartupActivitiesPassed(project);
@@ -540,8 +543,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
isMappingLoaded.blockingGet(60000);
}
catch (TimeoutException | ExecutionException e) {
reportError("Cannot initialize vcs mapping");
gracefulExit();
onFailure(InspectionsBundle.message("inspection.application.cannot.initialize.vcs.mapping"));
}
}
runAnalysisAfterShelvingSync(
@@ -694,8 +696,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
if (!GlobalInspectionContextUtil.canRunInspections(project, false, () -> {
})) {
gracefulExit();
return;
onFailure(InspectionsBundle.message("inspection.application.cannot.configure.project.to.run.inspections"));
}
context.launchInspectionsOffline(scope, resultsDataPath, myRunGlobalToolsOnly, inspectionsResults);
reportMessage(1, "\n" + InspectionsBundle.message("inspection.capitalized.done") + "\n");
@@ -809,12 +810,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
if (profileName != null && !profileName.isEmpty()) {
InspectionProfileImpl inspectionProfile = loadProfileByName(project, profileName);
if (inspectionProfile == null) {
reportError("Profile with configured name (" +
profileName +
") was not found (neither in project nor in config directory). Configured by: " +
configSource);
gracefulExit();
return null;
onFailure(InspectionsBundle.message("inspection.application.profile.was.not.found.by.name.0.1", profileName, configSource));
}
return inspectionProfile;
}
@@ -822,9 +818,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
if (profilePath != null && !profilePath.isEmpty()) {
InspectionProfileImpl inspectionProfile = loadProfileByPath(profilePath);
if (inspectionProfile == null) {
reportError("Failed to load profile from '" + profilePath + "'. Configured by: " + configSource);
gracefulExit();
return null;
onFailure(InspectionsBundle.message("inspection.application.profile.failed.configure.by.path.0.1", profilePath, configSource));
}
return inspectionProfile;
}
@@ -861,7 +855,7 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
}
private ConversionListener createConversionListener() {
private ConversionListener createConversionListener(StringBuilder errorBuffer) {
return new ConversionListener() {
@Override
public void conversionNeeded() {
@@ -877,7 +871,8 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
@Override
public void error(@NotNull String message) {
reportError(InspectionsBundle.message("inspection.application.cannot.convert.project.0", message));
errorBuffer.append(InspectionsBundle.message("inspection.application.cannot.convert.project.0", message))
.append(System.lineSeparator());
}
@Override
@@ -886,8 +881,10 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
for (Path file : readonlyFiles) {
files.append(file.toString()).append("; ");
}
reportError(InspectionsBundle
.message("inspection.application.cannot.convert.the.project.the.following.files.are.read.only.0", files.toString()));
errorBuffer.append(InspectionsBundle
.message("inspection.application.cannot.convert.the.project.the.following.files.are.read.only.0",
files.toString()))
.append(System.lineSeparator());
}
};
}
@@ -912,6 +909,15 @@ public class InspectionApplicationBase implements CommandLineInspectionProgressR
}
}
public void reportError(@NotNull Throwable e) {
reportError(e.getMessage());
}
public void onFailure(@NotNull String message) {
reportError(message);
gracefulExit();
}
@Override
public void reportError(String message) {
System.err.println(message);