Skip to content

Commit 9071988

Browse files
committed
refactor(livesync): error handling shows file name that operation failed for
1 parent 7e28b07 commit 9071988

File tree

1 file changed

+8
-7
lines changed

1 file changed

+8
-7
lines changed

test-app/app/src/debug/java/com/tns/NativeScriptSyncService.java

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -138,9 +138,10 @@ public void run() {
138138
} else if (operation == CREATE_FILE_OPERATION) {
139139

140140
String fileName = getFileName();
141-
byte[] content = getFileContent();
141+
byte[] content = getFileContent(fileName);
142142
createOrOverrideFile(fileName, content);
143143

144+
144145
} else if (operation == DEFAULT_OPERATION) {
145146
logger.write("LiveSync: input stream is empty!");
146147
break;
@@ -222,32 +223,32 @@ private String getFileName() {
222223
return fileName.trim();
223224
}
224225

225-
private byte[] getFileContent() throws IOException {
226+
private byte[] getFileContent(String fileName) throws IllegalStateException {
226227
byte[] contentBuff;
227228
int contentL = -1;
228229
byte[] contentLength;
229230
try {
230231
contentLength = readNextBytes(CONTENT_LENGTH_BYTE_SIZE);
231232
} catch (Exception e) {
232-
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s. %s\noriginal exception: %s", FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION, e.toString()));
233+
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s %s. %s\noriginal exception: %s", fileName, FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION, e.toString()));
233234
}
234235

235236
if (contentLength == null) {
236-
throw new IllegalStateException(String.format("\nLiveSync: Missing %s bytes. %s", FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION));
237+
throw new IllegalStateException(String.format("\nLiveSync: Missing %s bytes. Did you send %s %s? %s", FILE_CONTENT_LENGTH, fileName, FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION));
237238
}
238239

239240
try {
240241
contentL = Integer.parseInt(new String(contentLength));
241242
contentBuff = readNextBytes(contentL);
242243

243244
} catch (NumberFormatException e) {
244-
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s. %s\noriginal exception: %s", FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION, e.toString()));
245+
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s %s. %s\noriginal exception: %s", fileName, FILE_CONTENT_LENGTH, LIVESYNC_ERROR_SUGGESTION, e.toString()));
245246
} catch (Exception e) {
246-
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s. %s\noriginal exception: %s", FILE_CONTENT, LIVESYNC_ERROR_SUGGESTION, e.toString()));
247+
throw new IllegalStateException(String.format("\nLiveSync: failed to parse %s %s. %s\noriginal exception: %s", fileName, FILE_CONTENT, LIVESYNC_ERROR_SUGGESTION, e.toString()));
247248
}
248249

249250
if (contentBuff == null) {
250-
throw new IllegalStateException(String.format("\nLiveSync: Missing %s bytes. %s", FILE_CONTENT, LIVESYNC_ERROR_SUGGESTION));
251+
throw new IllegalStateException(String.format("\nLiveSync: Missing %s bytes. Did you send %s %s? %s", FILE_CONTENT, fileName, FILE_CONTENT, LIVESYNC_ERROR_SUGGESTION));
251252
}
252253

253254
return contentBuff;

0 commit comments

Comments
 (0)