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

JBEAP-26402: handle badly formatted artifact cache #540

Merged
merged 1 commit into from
Feb 6, 2024

Conversation

michpetrov
Copy link
Contributor

Issue: JBEAP-26402

Copy link
Collaborator

@spyrkob spyrkob left a comment

Choose a reason for hiding this comment

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

Thanks @michpetrov. A couple of comments, plus could you port it to 1.1.x branch as well please?

@@ -205,6 +205,9 @@ private void init() throws IOException {
final List<String> lines = Files.readAllLines(artifactLog);
for (String line : lines) {
final String[] splitLine = line.split(ArtifactCache.CACHE_LINE_SEPARATOR);
if (splitLine.length < 3) {
throw new MavenUniverseException("Bad record format");
Copy link
Collaborator

Choose a reason for hiding this comment

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

Can you add this to the translations in ProsperoLogger with a bit more context please. Maybe something like "Bad artifact record format in the cache descriptor: %s"

Also I think just a base IOException would be better, it has nothing to do with MavenUniverse

Copy link
Contributor Author

Choose a reason for hiding this comment

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

If I add this to the logger what about the IOE in the catch block? I'd assume we want the top message to be the same, i.e. "can't read cache".

Copy link
Collaborator

Choose a reason for hiding this comment

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

ah good point, I remember why it was using MavenUniverseException. It's the top level catch that should have a more descriptive 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.

@spyrkob well what messages do you want me to change then?

Copy link
Collaborator

Choose a reason for hiding this comment

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

@michpetrov the one in throw new IOException("Unable to read cached items.", e); if you don't mind adding this to this PR

Path newFolder = temp.newFolder().toPath();
Files.createDirectories(newFolder.resolve(ArtifactCache.CACHE_FOLDER));
Files.writeString(newFolder.resolve(ArtifactCache.CACHE_FOLDER).resolve(ArtifactCache.CACHE_FILENAME),"badformat");
try {
Copy link
Collaborator

Choose a reason for hiding this comment

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

you can use following instead

assertThatThrownBy(() -> { ArtifactCache.getInstance(newFolder)})
  .isInstanceOf(IOException.class)
  .hasMessageContaining("Bad record format");

@michpetrov
Copy link
Contributor Author

@spyrkob does this work? I'll port it to 1.1.x if there're no further requests.

Copy link
Collaborator

@spyrkob spyrkob left a comment

Choose a reason for hiding this comment

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

Thanks @michpetrov that looks great!

@michpetrov michpetrov changed the title JBEAP-24602: handle badly formatted artifact cache JBEAP-26402: handle badly formatted artifact cache Jan 23, 2024
@spyrkob spyrkob merged commit c1b7a68 into wildfly-extras:main Feb 6, 2024
5 checks passed
@michpetrov michpetrov deleted the jbeap-24602 branch February 6, 2024 13:37
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