Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Improve error mesage on save, add current field content #4710

Merged
merged 3 commits into from
Mar 3, 2019
Merged
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
14 changes: 7 additions & 7 deletions src/main/java/org/jabref/logic/bibtex/LatexFieldFormatter.java
Original file line number Diff line number Diff line change
Expand Up @@ -48,26 +48,26 @@ private static void checkBraces(String text) throws InvalidFieldValueException {
char item = text.charAt(i);

boolean charBeforeIsEscape = false;
if (i > 0 && text.charAt(i - 1) == '\\') {
if ((i > 0) && (text.charAt(i - 1) == '\\')) {
charBeforeIsEscape = true;
}

if (!charBeforeIsEscape && item == '{') {
if (!charBeforeIsEscape && (item == '{')) {
left++;
} else if (!charBeforeIsEscape && item == '}') {
} else if (!charBeforeIsEscape && (item == '}')) {
right++;
}
}

// Then we throw an exception if the error criteria are met.
if (!(right == 0) && (left == 0)) {
throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely.");
throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text);
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

there should be a space after ", right?

}
if (!(right == 0) && (right < left)) {
throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely.");
throw new InvalidFieldValueException("Unescaped '}' character without opening bracket ends string prematurely. Field value: "+ text);
}
if (left != right) {
throw new InvalidFieldValueException("Braces don't match.");
throw new InvalidFieldValueException("Braces don't match. Field value: " + text);
}
}

Expand Down Expand Up @@ -148,7 +148,7 @@ private String formatAndResolveStrings(String content, String fieldName) throws
throw new InvalidFieldValueException(
"The # character is not allowed in BibTeX strings unless escaped as in '\\#'.\n"
+ "In JabRef, use pairs of # characters to indicate a string.\n"
+ "Note that the entry causing the problem has been selected.");
+ "Note that the entry causing the problem has been selected. Field value: "+content);
}
}
}
Expand Down