Skip to content

Commit

Permalink
feat: improve error handling during submission
Browse files Browse the repository at this point in the history
  • Loading branch information
netomi committed Jan 8, 2024
1 parent 81497cf commit e5cba2c
Show file tree
Hide file tree
Showing 5 changed files with 43 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -122,6 +122,10 @@ public InputStream stdoutAsStream() throws IOException {
return Files.newInputStream(stdout, StandardOpenOption.READ);
}

public InputStream stderrAsStream() throws IOException {
return Files.newInputStream(stderr, StandardOpenOption.READ);
}

Result log() {
LOGGER.trace(this.toString());
if (exitValue == 0) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,14 +7,17 @@
*******************************************************************************/
package org.eclipse.cbi.ws.macos.notarization.xcrun.notarytool;

import com.google.common.base.Charsets;
import com.google.common.collect.ImmutableList;
import com.google.common.io.CharStreams;
import org.eclipse.cbi.ws.macos.notarization.process.NativeProcess;
import org.eclipse.cbi.ws.macos.notarization.xcrun.common.*;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.xml.sax.SAXException;

import java.io.IOException;
import java.io.InputStreamReader;
import java.nio.file.Path;
import java.util.*;
import java.util.concurrent.ExecutionException;
Expand All @@ -36,7 +39,7 @@ protected List<String> getUploadCommand(String appleIDUsername, String appleIDPa
}

@Override
protected NotarizerResult analyzeSubmissionResult(NativeProcess.Result nativeProcessResult, Path fileToNotarize) throws ExecutionException {
protected NotarizerResult analyzeSubmissionResult(NativeProcess.Result nativeProcessResult, Path fileToNotarize) {
NotarizerResultBuilder resultBuilder = NotarizerResult.builder();
try {
PListDict plist = PListDict.fromXML(nativeProcessResult.stdoutAsStream());
Expand Down Expand Up @@ -66,7 +69,19 @@ protected NotarizerResult analyzeSubmissionResult(NativeProcess.Result nativePro
}
} catch (IOException | SAXException e) {
LOGGER.error("Error while parsing the output after the upload of '" + fileToNotarize + "' to the Apple notarization service", e);
throw new ExecutionException("Error while parsing the output after the upload of the file to be notarized", e);

String errorMessage;

try {
errorMessage =
CharStreams.toString(new InputStreamReader(nativeProcessResult.stderrAsStream(), Charsets.UTF_8));
} catch (IOException ex) {
errorMessage = "unknown error. See server log for more details.";
}

resultBuilder
.status(NotarizerResult.Status.UPLOAD_FAILED)
.message("Failed to notarize the requested file. Reason: " + errorMessage);
}
return resultBuilder.build();
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -17,8 +17,7 @@
import java.nio.file.Path;
import java.util.concurrent.ExecutionException;

import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.*;

public class NotarytoolNotarizerTest {

Expand Down Expand Up @@ -49,6 +48,26 @@ public void analyzeSuccessfulSubmission() throws ExecutionException {
assertEquals("Successfully uploaded file", result.message());
}

@Test
public void analyzeFailureSubmissionDueToRequiredAgreement() throws ExecutionException {
Path stdout = Path.of(this.getClass().getResource("submission-empty.log").getPath());
Path stderr = Path.of(this.getClass().getResource("submission-failure.log").getPath());

NativeProcess.Result r =
NativeProcess.Result.builder()
.exitValue(0)
.arg0("")
.stdout(stdout)
.stderr(stderr)
.build();

NotarizerResult result = tool.analyzeSubmissionResult(r, Path.of("SuperDuper.dmg"));

assertEquals(NotarizerResult.Status.UPLOAD_FAILED, result.status());
assertTrue(result.message().startsWith("Failed to notarize the requested file. Reason: Error: " +
"HTTP status code: 403. A required agreement is missing or has expired."));
}

@Test
public void analyzeInfoInProgress() throws ExecutionException {
Path stdout = Path.of(this.getClass().getResource("info-in-progress.log").getPath());
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Error: HTTP status code: 403. A required agreement is missing or has expired. This request requires an in-effect agreement that has not been signed or has expired. Ensure your team has signed the necessary legal agreements and that they are not expired.

0 comments on commit e5cba2c

Please sign in to comment.