changeset 485:cdd53e5884ae

Do not add anything to exception message in case no details are known
author Artem Tikhomirov <tikhomirov.artem@gmail.com>
date Thu, 09 Aug 2012 15:45:18 +0200
parents ae4d6604debd
children d740edfff563
files src/org/tmatesoft/hg/internal/ExceptionInfo.java src/org/tmatesoft/hg/repo/HgRuntimeException.java
diffstat 2 files changed, 33 insertions(+), 32 deletions(-) [+]
line wrap: on
line diff
--- a/src/org/tmatesoft/hg/internal/ExceptionInfo.java	Wed Aug 08 14:41:44 2012 +0200
+++ b/src/org/tmatesoft/hg/internal/ExceptionInfo.java	Thu Aug 09 15:45:18 2012 +0200
@@ -121,35 +121,35 @@
 			sb.append(';');
 			sb.append(' ');
 		}
-		sb.append("rev:");
-		boolean needNodeid = true;
-		if (isRevisionIndexSet()) {
-			if (rangeLeftBoundary != BAD_REVISION || rangeRightBoundary != BAD_REVISION) {
-				String sr;
-				switch (getRevisionIndex()) {
-				case BAD_REVISION:
-					sr = "UNKNOWN"; break;
-				case TIP:
-					sr = "TIP"; break;
-				case WORKING_COPY:
-					sr = "WORKING-COPY"; break;
-				case NO_REVISION:
-					sr = "NO REVISION"; break;
-				default:
-					sr = String.valueOf(getRevisionIndex());
-				}
-				sb.append(String.format("%s is not from [%d..%d]", sr, rangeLeftBoundary, rangeRightBoundary));
-			} else {
-				sb.append(getRevisionIndex());
-				if (isRevisionSet()) {
-					sb.append(':');
-					sb.append(getRevision().shortNotation());
-					needNodeid = false;
+		if (isRevisionIndexSet() || isRevisionSet()) {
+			if (isRevisionIndexSet()) {
+				if (rangeLeftBoundary != BAD_REVISION || rangeRightBoundary != BAD_REVISION) {
+					String sr;
+					switch (getRevisionIndex()) {
+					case BAD_REVISION:
+						sr = "UNKNOWN"; break;
+					case TIP:
+						sr = "TIP"; break;
+					case WORKING_COPY:
+						sr = "WORKING-COPY"; break;
+					case NO_REVISION:
+						sr = "NO REVISION"; break;
+					default:
+						sr = String.valueOf(getRevisionIndex());
+					}
+					sb.append(String.format("%s is not from [%d..%d]", sr, rangeLeftBoundary, rangeRightBoundary));
+				} else {
+					sb.append("rev:");
+					sb.append(getRevisionIndex());
+					if (isRevisionSet()) {
+						sb.append(':');
+						// fall-through to get revision appended
+					}
 				}
 			}
-		}
-		if (isRevisionSet() && needNodeid) {
-			sb.append(getRevision().shortNotation());
+			if (isRevisionSet()) {
+				sb.append(getRevision().shortNotation());
+			}
 		}
 		if (localFile != null) {
 			sb.append(';');
--- a/src/org/tmatesoft/hg/repo/HgRuntimeException.java	Wed Aug 08 14:41:44 2012 +0200
+++ b/src/org/tmatesoft/hg/repo/HgRuntimeException.java	Thu Aug 09 15:45:18 2012 +0200
@@ -90,11 +90,12 @@
 
 	@Override
 	public String toString() {
-		StringBuilder sb = new StringBuilder(super.toString());
-		sb.append(' ');
-		sb.append('(');
+		String base = super.toString();
+		StringBuilder sb = new StringBuilder();
 		details.appendDetails(sb);
-		sb.append(')');
-		return sb.toString();
+		if (sb.length() == 0) {
+			return base;
+		}
+		return new StringBuilder(base).append(' ').append('(').append(sb).append(')').toString();
 	}
 }