-
Notifications
You must be signed in to change notification settings - Fork 23
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
Refactoring the TestCaseParseResult #444
base: development
Are you sure you want to change the base?
Refactoring the TestCaseParseResult #444
Conversation
98c47ab
to
83189ac
Compare
return@ca | ||
} | ||
|
||
val currentTest = result.testCase!! | ||
val currentTest = result.content!! |
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.
Risky, because there is nothing that prevents content
from being null
, which would lead to an NPE.
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.
As a rule, no !!
in any code that goes in development
. Otherwise, one of the strongest aspects of Kotlin, null-safety, just vanishes.
val errorOccurred: Boolean, | ||
data class OperationResult<Payload>( | ||
val content: Payload? = null, | ||
val error: ErrorDetails? = null, |
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.
I am not particularly happy with this API, because it implies IMHO an implicit contract that cannot easily be stated explicitly or enforced:
In my understanding the assumption is that either content
or error
are set. There is, however, nothing that enforces me to do this—both could be null
or set. I am now thinking about how such an API could/should actually look like. Personally, I am in favour of something that does not require such an implicit contract:
data class OperationResult(val result: ElementType)
interface ElementType {}
data class Result(val result: Payload) : ElementType
data class Error(val message: String) : ElementType
Please do not take this API for granted, it's just a proposal of my idea for discussion. Additionally, one would probably want to have this OperationResult
type then available in some more global package of TestSpark.
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.
Here is a possible implementation:
sealed interface Result<out ValueType, out ErrorType> {
data class Ok<ValueType>(val value: ValueType): Result<ValueType, Nothing>
data class Error<ErrorType>(val error: ErrorType): Result<Nothing, ErrorType>
}
and then you write extension methods for result checking & retrieval.
Description of changes made
Replace OperationResult to TestCaseParseResult to improve error mangment.
Other notes
Closes #293