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

Feature/test #9

Merged
merged 7 commits into from
Oct 16, 2024
Merged

Feature/test #9

merged 7 commits into from
Oct 16, 2024

Conversation

JesusMcCloud
Copy link
Collaborator

  • migrate to dokka 2 for documentation
  • multi-module project setup
  • introduce kmmresult-test, enabling
    • result should succeed
    • result shouldNot succeed
    • result shouldSucceedWith expectedValue
  • remove Arrow dependency and import arrow's list of Fatal exceptions directly into our code
  • Introduce [Result.nonFatalOrThrow] to mimic KmmResult's non-fatal-only behaviour, but without the object instantiation overhead

@iaik-jheher
Copy link
Contributor

would result.shouldSucceed() which returns the contained value (or throws) be useful?

@JesusMcCloud
Copy link
Collaborator Author

done

@iaik-jheher
Copy link
Contributor

iaik-jheher commented Oct 14, 2024

maybe a more "natural" way to avoid forgetting .nonFatalOrThrow internally... runCatchingNonFatal? (it's a mouthful, maybe find a shorter name?)

@iaik-jheher
Copy link
Contributor

so just a shorthand for runCatching { ... }.nonFatalOrThrow()

@@ -0,0 +1 @@
rootProject.name = 'backend_buildSrc'
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why backend?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

overlooked this. renamed

@@ -0,0 +1,29 @@
object VersionsBackend {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why backend?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

totally forgot to remove the actual sources. in the buildSrc. buildSrc is needed becasue dokka only works from plugins (such as our conventions, or buildSrc) for multi-module projects)

const val attestation = "2.1.3"
const val jose = "9.25.6"

object spring {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

why do we need spring dependency declarations here?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

removed

artifactVersion = 1.8.0
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Non-snapshot version on development?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

i really should rename the default branch to main and create a proper development branch. Will do after squashing and merging this.

@JesusMcCloud
Copy link
Collaborator Author

@iaik-jheher

maybe a more "natural" way to avoid forgetting .nonFatalOrThrow internally... runCatchingNonFatal? (it's a mouthful, maybe find a shorter name?)

My issue with this proposal is that it makes it easy to accidentally expose a Result, when you really want a KmmResult for your public API. After all, you'd then have two functions:

  • catching
  • nonFatalCatching or runCatchinNonFatal

Both will be rethrowing fatal exceptions, but only has it in its name. I don't see how to solve that issue, because even if we rename catching (which we cannot, because it would break evrything)m it won't change the fact that we'd end up with a confusing API.
Result is borked and we can't fix it. We can only offer a band-aid and .nonFatalOrThrow() is pretty expressive in that repsect.

@iaik-jheher
Copy link
Contributor

i thought the intent of nonFatalOrThrow was that we could "safely" use Result internally to avoid overhead; did I misunderstand this?

@JesusMcCloud
Copy link
Collaborator Author

i thought the intent of nonFatalOrThrow was that we could "safely" use Result internally to avoid overhead; did I misunderstand this?

Yes it is and this is what it does. What is the issue?

@iaik-jheher
Copy link
Contributor

I don't think using it internally is safe if forgetting nonFatalOrThrow is an undetectable footgun...

@iaik-jheher
Copy link
Contributor

(That was the thought process behind my suggestion for a runCatching replacement)

@JesusMcCloud
Copy link
Collaborator Author

Fair point, but how to not make the API confusing?

@JesusMcCloud
Copy link
Collaborator Author

thinking about how the IDE behaves, autocomplete, etc. maybe catchingResult is the best we can do?

@iaik-jheher
Copy link
Contributor

maybe catchingUnwrap or something? it's semantically equivalent to catching { }.unwrap() just without construction overhead

@JesusMcCloud
Copy link
Collaborator Author

I went with catchingUnwrapped

@@ -268,7 +268,7 @@ inline fun <R, T : R> KmmResult<T>.recoverCatching(block: (error: Throwable) ->
/**
* Non-fatal-only-catching version of stdlib's [runCatching], directly returning a [KmmResult] --
* Re-throws any fatal exceptions, such as `OutOfMemoryError`. Relies on [Arrow](https://arrow-kt.io)'s
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) internally.
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This doesn't make it clear that Arrow is not a dependency imo, and where we took the list from doesn't really matter enough that we'd put it in the docs.

How about A list of fatal exceptions is [here](https://github.com/a-sit-plus/KmmResult/tree/main/bla/blub).?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I want to give credit, where credit is due. how about "Mirrors Arrow's logic"

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

if you link to our source for nonFatalOrThrow, the comment there references arrow; is that not enough?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I'm gonna go with re-iplements Arrow's logic to avoid a dependency on Arrow for a single function.

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

sounds good to me

expect inline fun Throwable.nonFatalOrThrow(): Throwable

/**
* Helper to effectively convert stdlib's [runCatching] to behave like KmmResults Non-fatal-only [catching]. I.e. any
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

KmmResult's, apostrophe

Comment on lines 7 to 14
* Throws any fatal exceptions. This is a re-implementation taken from Arrow's
* [`nonFatalOrThrow`](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) –
* not because it is bad, it is actually pretty much perfect.
* However, the arrow dependency triggered an obscure IDEA bug, resulting in `NoClasDefFoundErrors` instead of correct
* behaviour. * We therefore removed the dependency and added the functionality directly to KmmResult.
*
* Please note that this was never a problem building anything that depended on KmmResult, it only made debugging
* in IDEA a nightmare.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

this feels like far too much exposition for an apidoc comment

/**
* Non-fatal-only-catching version of stdlib's [runCatching], returning a [Result] --
* Re-throws any fatal exceptions, such as `OutOfMemoryError`. Relies on [Arrow](https://arrow-kt.io)'s
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same point as with catching

* Non-fatal-only-catching version of stdlib's [runCatching] (calling the specified function [block] with `this` value
* as its receiver), directly returning a [Result] --
* Re-throws any fatal exceptions, such as `OutOfMemoryError`. Relies on [Arrow](https://arrow-kt.io)'s
* [nonFatalOrThrow](https://apidocs.arrow-kt.io/arrow-core/arrow.core/non-fatal-or-throw.html) logic.
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

same

@JesusMcCloud JesusMcCloud merged commit b8111e2 into development Oct 16, 2024
3 checks passed
@JesusMcCloud JesusMcCloud deleted the feature/test branch October 16, 2024 13:27
JesusMcCloud added a commit that referenced this pull request Oct 16, 2024
- migrate to dokka 2 for documentation
- multi-module project setup
- introduce `kmmresult-test`, featuring
  - `result should succeed`
  - `result shouldNot succeed`
  - `result shouldSucceedWith expectedValue`
  - `result.shouldSucceed()` returning the contained value
- remove Arrow dependency and import arrow's list of Fatal exceptions directly into our code
- Introduce `Result.nonFatalOrThrow` to mimic KmmResult's non-fatal-only behaviour, but without the object instantiation overhead
- Introduce `carchingUnwrapped`, which mimics KmmResult's non-fatal-only behaviour, but without the object instantiation overhead
JesusMcCloud added a commit that referenced this pull request Oct 16, 2024
- migrate to dokka 2 for documentation
- multi-module project setup
- introduce `kmmresult-test`, featuring
  - `result should succeed`
  - `result shouldNot succeed`
  - `result shouldSucceedWith expectedValue`
  - `result.shouldSucceed()` returning the contained value
- remove Arrow dependency and import arrow's list of Fatal exceptions directly into our code
- Introduce `Result.nonFatalOrThrow` to mimic KmmResult's non-fatal-only behaviour, but without the object instantiation overhead
- Introduce `carchingUnwrapped`, which mimics KmmResult's non-fatal-only behaviour, but without the object instantiation overhead
@JesusMcCloud JesusMcCloud mentioned this pull request Oct 25, 2024
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.

3 participants