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

Chunked response errors should fail plugin execution #168

Merged
merged 1 commit into from May 15, 2015
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jolokia.docker.maven.access.chunked;

import org.jolokia.docker.maven.access.DockerAccessException;
import org.jolokia.docker.maven.util.Logger;
import org.json.JSONObject;

Expand All @@ -12,13 +13,19 @@ public BuildResponseHandler(Logger log) {
}

@Override
public void process(JSONObject json) {
public void process(JSONObject json) throws DockerAccessException {
if (json.has("error")) {
log.error("Error building image: " + json.get("error"));
String msg = json.getString("error");
log.error("Error building image: " + msg);

String detailMsg = "";
if (json.has("errorDetail")) {
JSONObject details = json.getJSONObject("errorDetail");
log.error(details.getString("message"));
detailMsg = details.getString("message");
log.error(detailMsg);
}
throw new DockerAccessException("%s %s", json.get("error"),
(msg.equals(detailMsg) || "".equals(detailMsg) ? "" : "(" + detailMsg + ")"));
} else if (json.has("stream")) {
String message = json.getString("stream");
log.verbose(message.trim());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jolokia.docker.maven.access.chunked;

import org.jolokia.docker.maven.access.DockerAccessException;

public interface ChunkedResponseHandler<T> {
void process(T toProcess);
void process(T toProcess) throws DockerAccessException;
Copy link
Contributor Author

Choose a reason for hiding this comment

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

Updating the interface contract to allow for exception throwing. DockerAccessException may not be the best choice based on its description, but everything seemed to funnel into it anyway, so I went with that instead of creating a whole new class of exception.

}
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jolokia.docker.maven.access.chunked;

import org.jolokia.docker.maven.access.DockerAccessException;

import java.io.IOException;
import java.io.InputStream;

Expand All @@ -13,7 +15,7 @@ public ChunkedResponseReader(InputStream stream, ChunkedResponseHandler<String>
this.handler = handler;
}

public void process() throws IOException {
public void process() throws IOException, DockerAccessException {
int len;
int size = 8129;
byte[] buf = new byte[size];
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jolokia.docker.maven.access.chunked;

import org.jolokia.docker.maven.access.DockerAccessException;
import org.jolokia.docker.maven.util.Logger;
import org.json.JSONObject;

Expand All @@ -14,7 +15,7 @@ public PullOrPushResponseHandler(Logger log) {
}

@Override
public void process(JSONObject json) {
public void process(JSONObject json) throws DockerAccessException {
if (json.has("progressDetail")) {
JSONObject details = json.getJSONObject("progressDetail");
if (details.has("total")) {
Expand All @@ -35,6 +36,7 @@ public void process(JSONObject json) {
String msg = json.getString("error").trim();
String details = json.getJSONObject("errorDetail").getString("message").trim();
log.error(msg + (msg.equals(details) ? "" : "(" + details + ")"));
throw new DockerAccessException("%s %s", msg, (msg.equals(details) ? "" : "(" + details + ")"));
} else {
log.info("... " + (json.has("id") ? json.getString("id") + ": " : "") + json.getString("status"));
}
Expand Down
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
package org.jolokia.docker.maven.access.chunked;

import org.jolokia.docker.maven.access.DockerAccessException;
import org.jolokia.docker.maven.util.Logger;
import org.json.JSONException;
import org.json.JSONObject;
Expand All @@ -16,7 +17,7 @@ public TextToJsonBridgeCallback(Logger log, ChunkedResponseHandler<JSONObject> h
}

@Override
public void process(String text) {
public void process(String text) throws DockerAccessException {
try {
JSONObject json = new JSONObject(text);
handler.process(json);
Expand Down