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

Refactoring the TestCaseParseResult #444

Open
wants to merge 2 commits into
base: development
Choose a base branch
from

Conversation

arksap2002
Copy link
Collaborator

Description of changes made

Replace OperationResult to TestCaseParseResult to improve error mangment.

Other notes

Closes #293

  • I have checked that I am merging into correct branch

@arksap2002 arksap2002 self-assigned this Feb 14, 2025
@arksap2002 arksap2002 changed the title replace TestCaseParseResult to OperationResult Refactoring the TestCaseParseResult Feb 14, 2025
@arksap2002 arksap2002 force-pushed the arksap2002/refactoring/improve-testCaseParseResult branch from 98c47ab to 83189ac Compare February 14, 2025 14:35
return@ca
}

val currentTest = result.testCase!!
val currentTest = result.content!!
Copy link
Collaborator

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.

Copy link
Collaborator

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,
Copy link
Collaborator

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.

Copy link
Collaborator

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.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Refactoring the TestCaseParseResult
3 participants