-
Notifications
You must be signed in to change notification settings - Fork 1k
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
refactor: Use DataValidationException to signal TripTime errors.
- Loading branch information
Showing
23 changed files
with
320 additions
and
162 deletions.
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
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
37 changes: 37 additions & 0 deletions
37
src/main/java/org/opentripplanner/framework/error/OtpError.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,37 @@ | ||
package org.opentripplanner.framework.error; | ||
|
||
import java.util.Locale; | ||
|
||
/** | ||
* A generic representation of an error. The error should have a code used to group the same | ||
* type of errors together. To avoid filling up memory with error strings during graph build | ||
* we store errors in memory "decomposed". The {@link #messageTemplate()} and | ||
* {@link #messageArguments()} is used to construct the message. Use the {@link Locale#ROOT} | ||
* when constructing the message - we only support english with SI formatting. | ||
*/ | ||
public interface OtpError { | ||
/** | ||
* An error code used to identify the error type. This is NOT an enum, but feel free | ||
* to use an inum in the implementation, then use the enum NAME as the code or | ||
* enum TYPE:NAME. Then name should be unique within OTP. | ||
*/ | ||
String errorCode(); | ||
|
||
/** | ||
* The string template used to create a human-readable error message. Use the | ||
* {@link String#format(Locale, String, Object...)} format. | ||
*/ | ||
String messageTemplate(); | ||
|
||
/** | ||
* The arguments to inject into the message. | ||
*/ | ||
Object[] messageArguments(); | ||
|
||
/** | ||
* Construct a message. | ||
*/ | ||
default String message() { | ||
return String.format(Locale.ROOT, messageTemplate(), messageArguments()); | ||
} | ||
} |
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
35 changes: 35 additions & 0 deletions
35
src/main/java/org/opentripplanner/transit/model/framework/DataValidationException.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,35 @@ | ||
package org.opentripplanner.transit.model.framework; | ||
|
||
import org.opentripplanner.framework.error.OtpError; | ||
|
||
/** | ||
* This class is used to throw a data validation exception. It holds an error witch can be | ||
* inserted into build issue store, into the updater logs or returned to the APIs. The framework | ||
* to catch and handle this is NOT IN PLACE, see | ||
* <a href="https://github.com/opentripplanner/OpenTripPlanner/issues/5070">Error code design #5070</a>. | ||
* <p> | ||
* MORE WORK ON THIS IS NEEDED! | ||
*/ | ||
public class DataValidationException extends RuntimeException { | ||
|
||
private final OtpError error; | ||
|
||
public DataValidationException(OtpError error) { | ||
super(); | ||
this.error = error; | ||
} | ||
|
||
public OtpError error() { | ||
return error; | ||
} | ||
|
||
@Override | ||
public String getMessage() { | ||
return error.message(); | ||
} | ||
|
||
@Override | ||
public String toString() { | ||
return getMessage(); | ||
} | ||
} |
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.