Skip to content

Commit

Permalink
Move exception reporting to debugtool
Browse files Browse the repository at this point in the history
  • Loading branch information
joeygrover committed May 20, 2021
1 parent d8c09da commit 2599121
Show file tree
Hide file tree
Showing 9 changed files with 23 additions and 25 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,6 @@ public String toString() {
}
if (detail != null) {
ret += "\nnested: " + detail.toString();
detail.printStackTrace();
}
return ret;
}
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -205,7 +205,7 @@ public void onResponse(int correlationId, RPCResponse response) {
try {
DebugTool.logInfo(TAG, response.serializeJSON().toString());
} catch (JSONException e) {
e.printStackTrace();
DebugTool.logError(TAG, "Error attempting to serialize ChangeRegistrationResponse", e);
}

// go through and change sdlManager properties that were changed via the LCU update
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@
import com.smartdevicelink.proxy.rpc.PutFile;
import com.smartdevicelink.proxy.rpc.PutFileResponse;
import com.smartdevicelink.proxy.rpc.listeners.OnRPCResponseListener;
import com.smartdevicelink.util.DebugTool;

import java.io.IOException;
import java.io.InputStream;
Expand Down Expand Up @@ -221,7 +222,7 @@ private void closeInputStream() {
try {
this.inputStream.close();
} catch (IOException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to close input stream", e);
}
}

Expand Down Expand Up @@ -330,7 +331,7 @@ private byte[] getDataChunkWithSize(int size, InputStream inputStream) {
try {
bytesRead = inputStream.read(buffer, 0, size);
} catch (IOException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to read from input stream", e);
}

if (bytesRead > 0) {
Expand Down Expand Up @@ -365,7 +366,7 @@ private int getFileSizeFromInputStream(InputStream inputStream) {
try {
size = inputStream.available();
} catch (IOException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error trying to get input stream size", e);
}
}
return size;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -146,7 +146,7 @@ public void start() {
try {
session.startSession();
} catch (SdlException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to start session", e);
}
}

Expand Down Expand Up @@ -851,7 +851,7 @@ private void sendRPCMessagePrivate(RPCMessage message, boolean isInternalMessage
session.sendMessage(pm);

} catch (OutOfMemoryError e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to send RPC message.", e);
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -1275,7 +1275,7 @@ public void onResponse(int correlationId, RPCResponse response) {
try {
DebugTool.logInfo(TAG, "Main Menu response: " + response.serializeJSON().toString());
} catch (JSONException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
}
} else {
DebugTool.logError(TAG, "Result: " + response.getResultCode() + " Info: " + response.getInfo());
Expand Down Expand Up @@ -1313,7 +1313,7 @@ public void onResponse(int correlationId, RPCResponse response) {
try {
DebugTool.logInfo(TAG, "Sub Menu response: " + response.serializeJSON().toString());
} catch (JSONException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
}
} else {
DebugTool.logError(TAG, "Failed to send sub menu commands: " + response.getInfo());
Expand Down Expand Up @@ -1365,7 +1365,7 @@ public void onResponse(int correlationId, RPCResponse response) {
try {
DebugTool.logInfo(TAG, "Dynamic Sub Menu response: " + response.serializeJSON().toString());
} catch (JSONException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to serialize JSON of RPC response", e);
}
} else {
DebugTool.logError(TAG, "Result: " + response.getResultCode() + " Info: " + response.getInfo());
Expand Down
12 changes: 7 additions & 5 deletions base/src/main/java/com/smartdevicelink/proxy/RPCStruct.java
Original file line number Diff line number Diff line change
Expand Up @@ -50,6 +50,8 @@
import java.util.Set;

public class RPCStruct implements Cloneable {
private static final String TAG = "RPCStruct";

public static final String KEY_BULK_DATA = "bulkData";
public static final String KEY_PROTECTED = "protected";

Expand Down Expand Up @@ -268,7 +270,7 @@ protected Object formatObject(Class tClass, Object obj) {

return customObject;
} catch (Exception e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to format an object from a Hashtable", e);
}
} else if (obj instanceof List<?>) {
List<?> list = (List<?>) obj;
Expand Down Expand Up @@ -300,7 +302,7 @@ protected Object formatObject(Class tClass, Object obj) {
}
newList.add(customObject);
} catch (Exception e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to format object from list of Hashtables", e);
return null;
}
}
Expand Down Expand Up @@ -334,15 +336,15 @@ protected Object getValueForString(Class tClass, String s) {
try {
valueForString = tClass.getDeclaredMethod("valueForString", String.class);
} catch (NoSuchMethodException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to find valueForString method in class", e);
}
if (valueForString != null) {
try {
return valueForString.invoke(null, (String) s);
} catch (IllegalAccessException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Illegal access while using reflection to get enum from string", e);
} catch (InvocationTargetException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error attempting to use method from reflection to get enum from string", e);
}
}
return null;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -179,11 +179,9 @@ private void handleBulkData(byte[] bulkData) {
tempBody = getBody(httpJson);
tempHeaders = getHeaders(httpJson);
} catch (JSONException e) {
DebugTool.logError(TAG, "HTTPRequest in bulk data was malformed.");
e.printStackTrace();
DebugTool.logError(TAG, "HTTPRequest in bulk data was malformed.", e);
} catch (NullPointerException e) {
DebugTool.logError(TAG, "Invalid HTTPRequest object in bulk data.");
e.printStackTrace();
DebugTool.logError(TAG, "Invalid HTTPRequest object in bulk data.", e);
}
} else if (RequestType.HTTP.equals(this.getRequestType())) {
tempHeaders = new Headers();
Expand All @@ -209,8 +207,7 @@ private String getBody(JSONObject httpJson) {
try {
result = httpJson.getString(KEY_BODY);
} catch (JSONException e) {
DebugTool.logError(TAG, KEY_BODY + " key doesn't exist in bulk data.");
e.printStackTrace();
DebugTool.logError(TAG, KEY_BODY + " key doesn't exist in bulk data.", e);
}

return result;
Expand All @@ -224,8 +221,7 @@ private Headers getHeaders(JSONObject httpJson) {
Hashtable<String, Object> httpHeadersHash = JsonRPCMarshaller.deserializeJSONObject(httpHeadersJson);
result = new Headers(httpHeadersHash);
} catch (JSONException e) {
DebugTool.logError(TAG, KEY_HEADERS + " key doesn't exist in bulk data.");
e.printStackTrace();
DebugTool.logError(TAG, KEY_HEADERS + " key doesn't exist in bulk data.", e);
}

return result;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -107,7 +107,7 @@ public static short disableSiphonServer() {
try {
SiphonServer.closeServer();
} catch (IOException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error while trying to close siphon server", e);
}

return m_listenPort;
Expand Down
2 changes: 1 addition & 1 deletion base/src/main/java/com/smartdevicelink/util/FileUtls.java
Original file line number Diff line number Diff line change
Expand Up @@ -74,7 +74,7 @@ public static byte[] getFileData(String filePath, String fileName) {
try {
return Files.readAllBytes(file.toPath());
} catch (IOException e) {
e.printStackTrace();
DebugTool.logError(TAG,"Error trying to get file data", e);
}
}
}
Expand Down

0 comments on commit 2599121

Please sign in to comment.