We don´t want to create a global enum with all error codes in the system. This creates an
unstable(change every time a new error code is added) central component. Also, it does not
communicate which errors may happen in each component. By component, I mean a logical
group of related packages and classes like the stop-model or the transit-model.
One way to do it is to create an interface which all error code enums inherit. For example:
package org.opentripplanner.transit.model.timetable;
/**
* Details about why a {@link TripTimes} instance is invalid.
*/
public enum TimeTableError implement OtpErrorCode {
NEGATIVE_DWELL_TIME,
NEGATIVE_HOP_TIME
}
}
Returning a Result type with a potential error is nice if the caller needs to take action, but
not if the caller must pass the result up the call chain. Many possible errors in a call-three
will make the results ugly. Most of the time the caller do not care what the error is, it will just
abort. A nicely designed exception hierarchy is much easier to maintain.
From @jtorin:
I second this approach. The enums are still nicely comparable, what you loose is that it's not possible to enumerate all values. Not really an issue in this case I think.
TODOs
[ ] Remember to refactor and remove: org.opentripplanner.transit.model.framework.Result
We don´t want to create a global enum with all error codes in the system. This creates an unstable(change every time a new error code is added) central component. Also, it does not communicate which errors may happen in each component. By component, I mean a logical group of related packages and classes like the stop-model or the transit-model.
One way to do it is to create an interface which all error code enums inherit. For example:
Returning a Result type with a potential error is nice if the caller needs to take action, but not if the caller must pass the result up the call chain. Many possible errors in a call-three will make the results ugly. Most of the time the caller do not care what the error is, it will just abort. A nicely designed exception hierarchy is much easier to maintain.
From @jtorin:
TODOs
org.opentripplanner.transit.model.framework.Result