Skip to content

Commit

Permalink
#400: Improve error handling for invalid package.json (#402)
Browse files Browse the repository at this point in the history
  • Loading branch information
kaklakariada authored Nov 4, 2022
1 parent dfbdb43 commit b465544
Show file tree
Hide file tree
Showing 23 changed files with 321 additions and 224 deletions.
295 changes: 147 additions & 148 deletions dependencies.md

Large diffs are not rendered by default.

51 changes: 48 additions & 3 deletions doc/changes/changes_2.9.1.md
Original file line number Diff line number Diff line change
@@ -1,56 +1,101 @@
# Project Keeper 2.9.1, released 2022-??-??
# Project Keeper 2.9.1, released 2022-11-04

Code name: Minor Changes
Code name: Bug Fixes

## Summary

Fixed some bugs.
Fixed bugs #397, #398 and #400, see below.

## Bug Fix

* #397: Categorized Go dependencies as 'unknown' if module name does not contain version number
* #398: Fixed dependency change report if file `package.json` or `go.mod` is missing in previous release.
* #400: Improved error handling for missing attributes in `package.json`.

## Dependency Updates

### Project-Keeper Shared Model Classes

#### Compile Dependency Updates

* Updated `com.exasol:error-reporting-java:0.4.1` to `1.0.0`
* Updated `org.eclipse.jgit:org.eclipse.jgit:6.2.0.202206071550-r` to `6.3.0.202209071007-r`

#### Test Dependency Updates

* Updated `nl.jqno.equalsverifier:equalsverifier:3.10.1` to `3.11`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.0` to `5.9.1`
* Updated `org.junit.jupiter:junit-jupiter-params:5.9.0` to `5.9.1`
* Updated `org.mockito:mockito-core:4.7.0` to `4.8.1`

### Project Keeper Core

#### Compile Dependency Updates

* Updated `com.exasol:error-reporting-java:0.4.1` to `1.0.0`
* Updated `com.exasol:project-keeper-shared-model-classes:2.9.0` to `2.9.1`
* Updated `org.glassfish.jaxb:jaxb-runtime:4.0.0` to `4.0.1`
* Updated `org.yaml:snakeyaml:1.32` to `1.33`

#### Runtime Dependency Updates

* Updated `com.exasol:project-keeper-java-project-crawler:2.9.0` to `2.9.1`

#### Test Dependency Updates

* Updated `com.exasol:maven-project-version-getter:1.1.1` to `1.2.0`
* Updated `com.exasol:project-keeper-shared-test-setup:2.9.0` to `2.9.1`
* Updated `nl.jqno.equalsverifier:equalsverifier:3.10.1` to `3.11`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.0` to `5.9.1`
* Updated `org.junit.jupiter:junit-jupiter-params:5.9.0` to `5.9.1`
* Updated `org.mockito:mockito-junit-jupiter:4.7.0` to `4.8.1`

### Project Keeper Command Line Interface

#### Compile Dependency Updates

* Updated `com.exasol:error-reporting-java:0.4.1` to `1.0.0`
* Updated `com.exasol:project-keeper-core:2.9.0` to `2.9.1`

#### Test Dependency Updates

* Updated `com.exasol:maven-project-version-getter:1.1.1` to `1.2.0`
* Updated `com.exasol:project-keeper-shared-test-setup:2.9.0` to `2.9.1`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.0` to `5.9.1`
* Updated `org.junit.jupiter:junit-jupiter-params:5.9.0` to `5.9.1`

### Project Keeper Maven Plugin

#### Compile Dependency Updates

* Updated `com.exasol:error-reporting-java:0.4.1` to `1.0.0`
* Updated `com.exasol:project-keeper-core:2.9.0` to `2.9.1`

#### Test Dependency Updates

* Updated `com.exasol:maven-project-version-getter:1.1.1` to `1.2.0`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.0` to `5.9.1`
* Updated `org.junit.jupiter:junit-jupiter-params:5.9.0` to `5.9.1`
* Updated `org.mockito:mockito-core:4.7.0` to `4.8.1`

### Project Keeper Java Project Crawler

#### Compile Dependency Updates

* Updated `com.exasol:error-reporting-java:0.4.1` to `1.0.0`
* Updated `com.exasol:project-keeper-shared-model-classes:2.9.0` to `2.9.1`
* Updated `org.eclipse.jgit:org.eclipse.jgit:6.2.0.202206071550-r` to `6.3.0.202209071007-r`

#### Test Dependency Updates

* Updated `com.exasol:maven-project-version-getter:1.1.1` to `1.2.0`
* Updated `org.junit.jupiter:junit-jupiter-engine:5.9.0` to `5.9.1`
* Updated `org.junit.jupiter:junit-jupiter-params:5.9.0` to `5.9.1`
* Updated `org.mockito:mockito-core:4.7.0` to `4.8.1`

### Project Keeper Shared Test Setup

#### Compile Dependency Updates

* Updated `com.exasol:project-keeper-shared-model-classes:2.9.0` to `2.9.1`
* Updated `org.yaml:snakeyaml:1.32` to `1.33`
8 changes: 1 addition & 7 deletions maven-project-crawler/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -50,12 +50,6 @@
<artifactId>maven-core</artifactId>
<scope>provided</scope>
</dependency>
<!-- overriding vulnerable transitive version -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>com.exasol</groupId>
<artifactId>maven-project-version-getter</artifactId>
Expand Down Expand Up @@ -123,4 +117,4 @@
</plugin>
</plugins>
</build>
</project>
</project>
25 changes: 9 additions & 16 deletions parent-pom/pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,10 @@
<properties>
<revision>2.9.1</revision>
<maven.version>3.8.6</maven.version>
<junit.version>5.9.0</junit.version>
<junit.platform.version>1.6.2</junit.platform.version>
<junit.version>5.9.1</junit.version>
<jacoco.version>0.8.8</jacoco.version>
<xmlunit.version>2.9.0</xmlunit.version>
<mockito.version>4.7.0</mockito.version>
<mockito.version>4.8.1</mockito.version>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<project.reporting.outputEncoding>UTF-8</project.reporting.outputEncoding>
<maven.compiler.source>11</maven.compiler.source>
Expand Down Expand Up @@ -119,7 +118,7 @@
<dependency>
<groupId>org.glassfish.jaxb</groupId>
<artifactId>jaxb-runtime</artifactId>
<version>4.0.0</version>
<version>4.0.1</version>
</dependency>
<dependency>
<groupId>org.xmlunit</groupId>
Expand All @@ -129,12 +128,12 @@
<dependency>
<groupId>com.exasol</groupId>
<artifactId>error-reporting-java</artifactId>
<version>0.4.1</version>
<version>1.0.0</version>
</dependency>
<dependency>
<groupId>org.eclipse.jgit</groupId>
<artifactId>org.eclipse.jgit</artifactId>
<version>6.2.0.202206071550-r</version>
<version>6.3.0.202209071007-r</version>
</dependency>
<dependency>
<groupId>net.steppschuh.markdowngenerator</groupId>
Expand All @@ -149,13 +148,7 @@
<dependency>
<groupId>org.yaml</groupId>
<artifactId>snakeyaml</artifactId>
<version>1.32</version>
</dependency>
<!-- overriding vulnerable transitive version -->
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>
<version>2.11.0</version>
<version>1.33</version>
</dependency>
<!-- test -->
<dependency>
Expand All @@ -174,7 +167,7 @@
<dependency>
<groupId>com.exasol</groupId>
<artifactId>maven-project-version-getter</artifactId>
<version>1.1.1</version>
<version>1.2.0</version>
<scope>test</scope>
</dependency>
<dependency>
Expand Down Expand Up @@ -246,7 +239,7 @@
<dependency>
<groupId>nl.jqno.equalsverifier</groupId>
<artifactId>equalsverifier</artifactId>
<version>3.10.1</version>
<version>3.11</version>
<scope>test</scope>
</dependency>
<!-- overriding vulnerable version -->
Expand All @@ -258,4 +251,4 @@
</dependency>
</dependencies>
</dependencyManagement>
</project>
</project>
Original file line number Diff line number Diff line change
Expand Up @@ -56,8 +56,9 @@ void runMainMethodWithNullArgumentFails() throws IOException, InterruptedExcepti
@Test
void verifyFailsForProjectWithoutGit() throws IOException, InterruptedException {
final Path projectDirRealPath = this.projectDir.toRealPath();
assertProcessFails("verify", "E-PK-CORE-90: Could not find .git directory in project-root " + projectDirRealPath
+ ". Known mitigations:\n* Run 'git init'.\n* Make sure that you run project-keeper only in the root directory of the git-repository. If you have multiple projects in that directory, define them in the '.project-keeper.yml'.");
assertProcessFails("verify", "E-PK-CORE-90: Could not find .git directory in project-root '"
+ projectDirRealPath
+ "'. Known mitigations:\n* Run 'git init'.\n* Make sure that you run project-keeper only in the root directory of the git-repository. If you have multiple projects in that directory, define them in the '.project-keeper.yml'.");
}

@Test
Expand Down
2 changes: 1 addition & 1 deletion project-keeper/error_code_config.yml
Original file line number Diff line number Diff line change
Expand Up @@ -2,4 +2,4 @@ error-tags:
PK-CORE:
packages:
- com.exasol.projectkeeper
highest-index: 162
highest-index: 164
Original file line number Diff line number Diff line change
Expand Up @@ -77,7 +77,7 @@ private String runCrawlerPlugin(final Path... pomFiles) {
if (!proc.waitFor(90, TimeUnit.SECONDS)) {
final String output = streamConsumer.getContent(STREAM_READING_TIMEOUT);
throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-81")
.message("Timeout while executing command {{executed command|uq}}. Output was {{output}}",
.message("Timeout while executing command {{executed command|u}}. Output was {{output}}",
commandParts, output)
.toString());
}
Expand All @@ -86,7 +86,7 @@ private String runCrawlerPlugin(final Path... pomFiles) {
if (exitCode != 0) {
LOGGER.log(Level.SEVERE, output);
throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-78").message(
"Failed to run command {{executed command|uq}}, exit code was {{exit code}}. Output:\n{{output}}",
"Failed to run command {{executed command|u}}, exit code was {{exit code}}. Output:\n{{output}}",
commandParts, exitCode, output).toString());
}
return new ResponseCoder().decodeResponse(output);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,7 +244,7 @@ private boolean fixFindings(final List<ValidationFinding> findings) {

for (final SimpleValidationFinding unfixedFinding : unfixedFindings) {
this.logger.warn(ExaError.messageBuilder("W-PK-CORE-67")
.message("Could not auto-fix: {{finding message|uq}}", unfixedFinding.getMessage()).toString());
.message("Could not auto-fix: {{finding message|u}}", unfixedFinding.getMessage()).toString());
}

if (blockers(unfixedFindings).isEmpty()) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -66,7 +66,7 @@ private IllegalArgumentException getSourceHasNoVersionException(final Path reque
.message(FAILED_TO_DETECT_VERSION
+ " The specified source with path {{path}} did not provide a version.", requestedPath)
.mitigation(
"Please specify a different source to read from or set an explicit version in your project-keeper config..")
"Please specify a different source to read from or set an explicit version in your project-keeper config.")
.toString());
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -217,7 +217,7 @@ private ProjectKeeperConfig.SourceType convertType(final String rawType) {
.map(String::toLowerCase).collect(Collectors.joining(", "));
throw new IllegalArgumentException(ExaError.messageBuilder("E-PK-CORE-84")
.message(INVALID_CONFIG_FILE + " Unsupported source type {{type}}.", rawType)
.mitigation("Please use one of the supported types: {{supported types|uq}}.", supportedTypes)
.mitigation("Please use one of the supported types: {{supported types|u}}.", supportedTypes)
.toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -99,7 +99,7 @@ private void validateUniqueSourcePaths(final List<Source> sources) {
.map(Entry::getKey).collect(toList());
if (!duplicatePaths.isEmpty()) {
throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-149")
.message("Sources use duplicate paths {{duplicate paths}}.", duplicatePaths)
.message("Sources use duplicate paths {{duplicate paths|u}}.", duplicatePaths)
.mitigation("Make sure that sources in .project-keeper.yml have unique paths.").toString());
}
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -131,7 +131,7 @@ private void waitForExecutionFinished(final Duration executionTimeout) {
try {
if (!this.process.waitFor(executionTimeout.toMillis(), TimeUnit.MILLISECONDS)) {
throw new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-128")
.message("Timeout while waiting {{timeout|uq}}ms for command {{executed command}}." //
.message("Timeout while waiting {{timeout|u}}ms for command {{executed command}}." //
+ " Output was {{output}}\nError output: {{std error}}", //
executionTimeout.toMillis(), formatCommand(), //
getOutputStreamContent(), getErrorStreamContent())
Expand All @@ -145,7 +145,7 @@ private void waitForExecutionFinished(final Duration executionTimeout) {
private RuntimeException handleInterruptedException(final InterruptedException exception) {
Thread.currentThread().interrupt();
return new IllegalStateException(ExaError.messageBuilder("E-PK-CORE-129")
.message("Interrupted while waiting for command {{executed command|uq}}", formatCommand()).toString(),
.message("Interrupted while waiting for command {{executed command|u}}", formatCommand()).toString(),
exception);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,11 +6,11 @@
import java.util.List;
import java.util.stream.Collectors;

import com.exasol.errorreporting.ExaError;
import com.exasol.projectkeeper.shared.dependencies.BaseDependency.Type;
import com.exasol.projectkeeper.shared.dependencies.VersionedDependency;

import jakarta.json.JsonObject;
import jakarta.json.JsonValue;
import jakarta.json.*;

final class PackageJsonReader {

Expand Down Expand Up @@ -38,7 +38,7 @@ static PackageJson read(final Path path, final String string) {

PackageJson read(final Path path, final JsonObject content) {
final String module = retrieveModuleName(content);
final String version = content.getString("version");
final String version = retrieveModuleVersion(content);
final List<VersionedDependency> dependencies = new ArrayList<>();
dependencies.addAll(versionedDependencies(content, DependencyKey.DEV));
dependencies.addAll(versionedDependencies(content, DependencyKey.COMPILE));
Expand All @@ -48,11 +48,27 @@ PackageJson read(final Path path, final JsonObject content) {
private static final String MODULE_PREFIX = "@exasol/";

private String retrieveModuleName(final JsonObject packageJson) {
final String raw = packageJson.getString("name");
if (!raw.startsWith(MODULE_PREFIX)) {
return raw;
final JsonString raw = packageJson.getJsonString("name");
if (raw == null) {
throw new IllegalArgumentException(
ExaError.messageBuilder("E-PK-CORE-163").message("Missing attribute 'name' in package.json.")
.mitigation("Add a 'name' attribute.").toString());
}
return raw.substring(MODULE_PREFIX.length());
final String rawString = raw.getString();
if (!rawString.startsWith(MODULE_PREFIX)) {
return rawString;
}
return rawString.substring(MODULE_PREFIX.length());
}

private String retrieveModuleVersion(final JsonObject content) {
final JsonString version = content.getJsonString("version");
if (version == null) {
throw new IllegalArgumentException(
ExaError.messageBuilder("E-PK-CORE-164").message("Missing attribute 'version' in package.json.")
.mitigation("Add a 'version' attribute.").toString());
}
return version.getString();
}

private List<VersionedDependency> versionedDependencies(final JsonObject packageJson, final DependencyKey key) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -55,13 +55,13 @@ public List<ValidationFinding> validate() {

private String getFileExistsErrorMessage(final Path fileThatMustNotExist, final String reason) {
return ExaError.messageBuilder("E-PK-CORE-26")
.message("{{FILE}} exists but must not exist. Reason: {{REASON|uq}}", fileThatMustNotExist.toString(),
.message("{{FILE}} exists but must not exist. Reason: {{REASON|u}}", fileThatMustNotExist.toString(),
reason)
.toString();
}

private SimpleValidationFinding.Fix getFix(final String fileName, final File file) {
return (Logger log) -> {
return (final Logger log) -> {
try {
Files.delete(file.toPath());
} catch (final IOException exception) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,8 @@
/**
* Validates if PK itself is up-to-date and performs self-update of called from a pom file.
*/
//[impl->dsn~verify-own-version~1]
//[impl->dsn~self-update~1]
// [impl->dsn~verify-own-version~1]
// [impl->dsn~self-update~1]
public class OwnVersionValidator implements Validator {

/**
Expand Down Expand Up @@ -101,7 +101,7 @@ private Version getLatestVersion(final MavenRepository repo) throws ValidationEx
} catch (final IOException | JsonContentException exception) {
throw new ValidationException(ExaError.messageBuilder("W-PK-CORE-155") //
.message("Could not detect latest available version of project-keeper.") //
.message(" {{message|uq}}.", exception.getMessage()) //
.message(" {{message|u}}.", exception.getMessage()) //
.mitigation("Please check network connection and response from {{url}}", repo.getUrl()) //
.toString(), exception);
}
Expand Down
Loading

0 comments on commit b465544

Please sign in to comment.