-
Notifications
You must be signed in to change notification settings - Fork 170
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
WIP Error and documentation overhaul #289
Merged
Merged
Changes from 1 commit
Commits
Show all changes
6 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,23 +1,22 @@ | ||
package com.hubspot.jinjava.interpret; | ||
|
||
import com.hubspot.jinjava.lib.Importable; | ||
|
||
public class InvalidArgumentException extends RuntimeException { | ||
|
||
private final int lineNumber; | ||
private final int startPosition; | ||
private final String message; | ||
private final String fieldName; | ||
|
||
public InvalidArgumentException(JinjavaInterpreter interpreter, String code, String message, String fieldName) { | ||
this.fieldName = fieldName; | ||
this.message = String.format("Invalid argument in %s: %s", code, message); | ||
public InvalidArgumentException(JinjavaInterpreter interpreter, Importable importable, InvalidReason invalidReason, int argumentNumber, Object... errorMessageArgs) { | ||
this.message = String.format("Invalid argument in '%s': %s", | ||
importable.getName(), | ||
String.format("%s %s", formatArgumentNumber(argumentNumber + 1), String.format(invalidReason.getErrorMessage(), errorMessageArgs))); | ||
|
||
this.lineNumber = interpreter.getLineNumber(); | ||
this.startPosition = interpreter.getPosition(); | ||
} | ||
|
||
public String getFieldName() { | ||
return fieldName; | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
@@ -29,4 +28,30 @@ public int getLineNumber() { | |
public int getStartPosition() { | ||
return startPosition; | ||
} | ||
|
||
private static String formatArgumentNumber(int argumentNumber) { | ||
switch (argumentNumber){ | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. this is not very i18nable, but in any case, you can do this for all numbers by just looking at the last digit of the int and using "st" if 1, "nd" if 2, "rd" if 3 and "th" for all other values. |
||
case 1: | ||
return "1st"; | ||
case 2: | ||
return "2nd"; | ||
case 3: | ||
return "3rd"; | ||
case 4: | ||
return "4th"; | ||
case 5: | ||
return "5th"; | ||
case 6: | ||
return "6th"; | ||
case 7: | ||
return "7th"; | ||
case 8: | ||
return "8th"; | ||
case 9: | ||
return "9th"; | ||
default: | ||
return String.valueOf(argumentNumber); | ||
|
||
} | ||
} | ||
} |
31 changes: 31 additions & 0 deletions
31
src/main/java/com/hubspot/jinjava/interpret/InvalidInputException.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,31 @@ | ||
package com.hubspot.jinjava.interpret; | ||
|
||
import com.hubspot.jinjava.lib.Importable; | ||
|
||
public class InvalidInputException extends RuntimeException { | ||
|
||
private final int lineNumber; | ||
private final int startPosition; | ||
private final String message; | ||
|
||
public InvalidInputException(JinjavaInterpreter interpreter, Importable importable, InvalidReason invalidReason, Object... errorMessageArgs) { | ||
this.message = String.format("Invalid input in '%s': input variable %s", | ||
importable.getName(), | ||
String.format(invalidReason.getErrorMessage(), errorMessageArgs)); | ||
|
||
this.lineNumber = interpreter.getLineNumber(); | ||
this.startPosition = interpreter.getPosition(); | ||
} | ||
|
||
public String getMessage() { | ||
return message; | ||
} | ||
|
||
public int getLineNumber() { | ||
return lineNumber; | ||
} | ||
|
||
public int getStartPosition() { | ||
return startPosition; | ||
} | ||
} |
23 changes: 23 additions & 0 deletions
23
src/main/java/com/hubspot/jinjava/interpret/InvalidReason.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,23 @@ | ||
package com.hubspot.jinjava.interpret; | ||
|
||
public enum InvalidReason { | ||
NUMBER_FORMAT("with value '%s' must be a number"), | ||
NULL("cannot be null"), | ||
STRING("must be a string"), | ||
EXPRESSION_TEST("with value %s must be the name of an expression test"), | ||
TEMPORAL_UNIT("with value %s must be a valid temporal unit"), | ||
JSON_READ("could not be converted to an object"), | ||
JSON_WRITE("object could not be written as a string"), | ||
REGEX("with value %s must be valid regex") | ||
; | ||
|
||
private final String errorMessage; | ||
|
||
InvalidReason(String errorMessage) { | ||
this.errorMessage = errorMessage; | ||
} | ||
|
||
public String getErrorMessage() { | ||
return errorMessage; | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
while you're in here, can you add a
required
attribute toJinjavaParam
? @williamspiro wanted one.There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Labeled all filter/exp tests with this new boolean value.