Display proper error message if non-existing/non-visible group is browsed

Browsing a group that does not exist or which is not visible for the
user fails and Gerrit shows the error message "Application Error,
Server Error, <group-id>". Since this error message looks like
something severe had gone wrong in Gerrit, this change implements
that now a proper error message is displayed in this case.
This fix is especially important since bug 797 allows a user to see
access rights for a group that is not visible to him and a link to
browse the group is provided which results in the error above if the
user clicks on it.

Bug: issue 804
Change-Id: Ieebdfd11cdea99e561bce49d09e83fbb10ada307
Signed-off-by: Edwin Kempin <edwin.kempin@sap.com>
This commit is contained in:
Edwin Kempin 2011-03-10 14:52:05 +01:00
parent 0ff5ff0112
commit ff2438231f
12 changed files with 32 additions and 8 deletions

View File

@ -12,7 +12,7 @@
// See the License for the specific language governing permissions and
// limitations under the License.
package com.google.gerrit.server.account;
package com.google.gerrit.common.errors;
import com.google.gerrit.reviewdb.AccountGroup;
@ -20,12 +20,14 @@ import com.google.gerrit.reviewdb.AccountGroup;
public class NoSuchGroupException extends Exception {
private static final long serialVersionUID = 1L;
public static final String MESSAGE = "Group Not Found: ";
public NoSuchGroupException(final AccountGroup.Id key) {
this(key, null);
}
public NoSuchGroupException(final AccountGroup.Id key, final Throwable why) {
super(key.toString(), why);
super(MESSAGE + key.toString(), why);
}
public NoSuchGroupException(final AccountGroup.NameKey k) {
@ -33,6 +35,6 @@ public class NoSuchGroupException extends Exception {
}
public NoSuchGroupException(final AccountGroup.NameKey k, final Throwable why) {
super(k.toString(), why);
super(MESSAGE + k.toString(), why);
}
}

View File

@ -46,6 +46,8 @@ public interface GerritConstants extends Constants {
String nameAlreadyUsedBody();
String noSuchAccountTitle();
String noSuchGroupTitle();
String inactiveAccountBody();
String menuAll();

View File

@ -29,6 +29,8 @@ notFoundBody = The page you requested was not found.
nameAlreadyUsedBody = The name is already in use.
noSuchAccountTitle = Code Review - Unknown User
noSuchGroupTitle = Code Review - Unknown Group
inactiveAccountBody = This user is currently inactive.
menuAll = All

View File

@ -22,4 +22,6 @@ public interface GerritMessages extends Messages {
String poweredBy(String version);
String noSuchAccountMessage(String who);
String noSuchGroupMessage(String who);
}

View File

@ -4,3 +4,5 @@ poweredBy = Powered by <a href="http://code.google.com/p/gerrit/" target="_blank
| <a href="http://code.google.com/p/gerrit/issues/list" target="_blank">Report Bug</a>
noSuchAccountMessage = {0} is not a registered user.
noSuchGroupMessage = Group {0} does not exist or is not visible to you.

View File

@ -21,6 +21,7 @@ import com.google.gerrit.common.errors.InactiveAccountException;
import com.google.gerrit.common.errors.NameAlreadyUsedException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.common.errors.NotSignedInException;
import com.google.gwt.core.client.GWT;
import com.google.gwt.user.client.rpc.AsyncCallback;
@ -51,6 +52,13 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
} else if (isNameAlreadyUsed(caught)) {
new ErrorDialog(Gerrit.C.nameAlreadyUsedBody()).center();
} else if (isNoSuchGroup(caught)) {
final String msg = caught.getMessage();
final String group = msg.substring(NoSuchGroupException.MESSAGE.length());
final ErrorDialog d = new ErrorDialog(Gerrit.M.noSuchGroupMessage(group));
d.setText(Gerrit.C.noSuchGroupTitle());
d.center();
} else if (caught instanceof ServerUnavailableException) {
new ErrorDialog(RpcConstants.C.errorServerUnavailable()).center();
@ -89,4 +97,9 @@ public abstract class GerritCallback<T> implements AsyncCallback<T> {
return caught instanceof RemoteJsonException
&& caught.getMessage().equals(NameAlreadyUsedException.MESSAGE);
}
private static boolean isNoSuchGroup(final Throwable caught) {
return caught instanceof RemoteJsonException
&& caught.getMessage().startsWith(NoSuchGroupException.MESSAGE);
}
}

View File

@ -17,11 +17,11 @@ package com.google.gerrit.httpd.rpc;
import com.google.gerrit.common.errors.CorruptEntityException;
import com.google.gerrit.common.errors.InvalidQueryException;
import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.CurrentUser;
import com.google.gerrit.server.IdentifiedUser;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gerrit.server.project.NoSuchChangeException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gwt.user.client.rpc.AsyncCallback;

View File

@ -20,6 +20,7 @@ import com.google.gerrit.common.errors.InactiveAccountException;
import com.google.gerrit.common.errors.NameAlreadyUsedException;
import com.google.gerrit.common.errors.NoSuchAccountException;
import com.google.gerrit.common.errors.NoSuchEntityException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.httpd.rpc.BaseServiceImplementation;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountGroup;
@ -31,7 +32,6 @@ import com.google.gerrit.server.account.AccountCache;
import com.google.gerrit.server.account.AccountResolver;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gerrit.server.account.Realm;
import com.google.gwt.user.client.rpc.AsyncCallback;
import com.google.gwtjsonrpc.client.VoidResult;

View File

@ -15,6 +15,7 @@
package com.google.gerrit.httpd.rpc.account;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountGroup;
@ -23,7 +24,6 @@ import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.account.AccountInfoCacheFactory;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;
import com.google.inject.assistedinject.Assisted;

View File

@ -16,13 +16,13 @@ package com.google.gerrit.httpd.rpc.account;
import com.google.gerrit.common.data.GroupDetail;
import com.google.gerrit.common.errors.NameAlreadyUsedException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.AccountGroupName;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.GroupControl;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gwtorm.client.OrmDuplicateKeyException;
import com.google.gwtorm.client.OrmException;
import com.google.inject.Inject;

View File

@ -18,6 +18,7 @@ import com.google.gerrit.common.data.ApprovalType;
import com.google.gerrit.common.data.ApprovalTypes;
import com.google.gerrit.common.data.ProjectDetail;
import com.google.gerrit.common.errors.InvalidNameException;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.httpd.rpc.Handler;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.reviewdb.ApprovalCategory;
@ -25,7 +26,6 @@ import com.google.gerrit.reviewdb.Project;
import com.google.gerrit.reviewdb.RefRight;
import com.google.gerrit.reviewdb.ReviewDb;
import com.google.gerrit.server.account.GroupCache;
import com.google.gerrit.server.account.NoSuchGroupException;
import com.google.gerrit.server.project.NoSuchProjectException;
import com.google.gerrit.server.project.NoSuchRefException;
import com.google.gerrit.server.project.ProjectCache;

View File

@ -14,6 +14,7 @@
package com.google.gerrit.server.account;
import com.google.gerrit.common.errors.NoSuchGroupException;
import com.google.gerrit.reviewdb.Account;
import com.google.gerrit.reviewdb.AccountGroup;
import com.google.gerrit.server.CurrentUser;