Skip to content

Commit

Permalink
Better error message when a file can not be found by ReviewBoard
Browse files Browse the repository at this point in the history
#130 - Can not show diff and create review request
  • Loading branch information
rombert committed Apr 5, 2014
1 parent 58445a1 commit 5ba5350
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 2 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
*/
public enum ErrorCode {

OBJECT_DOES_NOT_EXIST(100), INVALID_FORM_DATA(105);
OBJECT_DOES_NOT_EXIST(100), INVALID_FORM_DATA(105), FILE_NOT_FOUND(207);

private final int _errorCode;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -46,6 +46,7 @@
import org.review_board.ereviewboard.core.ReviewboardCorePlugin;
import org.review_board.ereviewboard.core.exception.ReviewboardApiException;
import org.review_board.ereviewboard.core.exception.ReviewboardException;
import org.review_board.ereviewboard.core.exception.ReviewboardFileNotFoundException;
import org.review_board.ereviewboard.core.exception.ReviewboardInvalidFormDataException;
import org.review_board.ereviewboard.core.exception.ReviewboardObjectDoesNotExistException;
import org.review_board.ereviewboard.core.model.*;
Expand Down Expand Up @@ -107,6 +108,9 @@ private JSONObject checkedGetJSonRootObject(String source) throws ReviewboardExc
throw new ReviewboardInvalidFormDataException(gatherFieldErrors(object));
else if ( ErrorCode.OBJECT_DOES_NOT_EXIST.is(code) )
throw new ReviewboardObjectDoesNotExistException(message);
else if (ErrorCode.FILE_NOT_FOUND.is(code))
throw new ReviewboardFileNotFoundException(object.getString("file"),
object.getString("revision"));

throw new ReviewboardApiException(message, code);
}
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,21 @@
package org.review_board.ereviewboard.core.exception;

import org.review_board.ereviewboard.core.client.ErrorCode;

/**
* The <tt>ReviewboardFileNotFoundException</tt> signals that a file that was
* referenced in an API call was not found
*
*/
public class ReviewboardFileNotFoundException extends ReviewboardApiException {

public ReviewboardFileNotFoundException() {

}

public ReviewboardFileNotFoundException(String fileName, String revision) {
super("No file named '" + fileName + "' found in the repository at revision '" + revision
+ "'", ErrorCode.FILE_NOT_FOUND.getErrorCode());
}

}
Original file line number Diff line number Diff line change
Expand Up @@ -44,7 +44,6 @@
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;


import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
Expand All @@ -59,6 +58,7 @@
import org.junit.Test;
import org.review_board.ereviewboard.core.ReviewboardAttributeMapper;
import org.review_board.ereviewboard.core.exception.ReviewboardException;
import org.review_board.ereviewboard.core.exception.ReviewboardFileNotFoundException;
import org.review_board.ereviewboard.core.exception.ReviewboardInvalidFormDataException;
import org.review_board.ereviewboard.core.model.*;
import org.review_board.ereviewboard.core.model.Change.Field;
Expand Down Expand Up @@ -494,6 +494,18 @@ public void readInvalidFormDataException() throws ReviewboardException, IOExcept
}
}

@Test
public void readFileNotFoundException() throws IOException, ReviewboardException {
try {
reader.ensureSuccess(readJsonTestResource("file-not-found.json"));
} catch (ReviewboardFileNotFoundException e) {
assertThat(
e.getMessage(),
is("No file named '/simple-project/w/runtime-ereviewboard/simple-project/src/com/example/Logic.java' found in the repository at revision '1'"));
assertThat(ErrorCode.FILE_NOT_FOUND.is(e.getCode()), is(true));
}
}

@Test
public void readChange() throws ReviewboardException, IOException {

Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
{"stat": "fail", "err": {"msg": "The file was not found in the repository", "code": 207}, "file": "/simple-project/w/runtime-ereviewboard/simple-project/src/com/example/Logic.java", "revision": "1"}

0 comments on commit 5ba5350

Please sign in to comment.