Skip to content

Commit

Permalink
Merge pull request #1561 from SpineEventEngine/do-not-log-error
Browse files Browse the repository at this point in the history
Do not log thrown `Mistake`
  • Loading branch information
alexander-yevsyukov authored Dec 15, 2024
2 parents 2692136 + b0c67ef commit d9fa60a
Show file tree
Hide file tree
Showing 8 changed files with 56 additions and 39 deletions.
7 changes: 4 additions & 3 deletions build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -30,11 +30,12 @@ import Build_gradle.Subproject
import io.spine.dependency.build.ErrorProne
import io.spine.dependency.lib.Grpc
import io.spine.dependency.lib.Guava
import io.spine.dependency.test.JUnit
import io.spine.dependency.lib.Kotlin
import io.spine.dependency.local.Spine
import io.spine.dependency.local.Logging
import io.spine.dependency.local.Spine
import io.spine.dependency.local.TestLib
import io.spine.dependency.local.Validation
import io.spine.dependency.test.JUnit
import io.spine.gradle.VersionWriter
import io.spine.gradle.checkstyle.CheckStyleConfig
import io.spine.gradle.github.pages.updateGitHubPages
Expand Down Expand Up @@ -251,7 +252,7 @@ fun Subproject.defineDependencies() {
implementation(Validation.runtime)

testImplementation(JUnit.runner)
testImplementation(Spine.testlib)
testImplementation(TestLib.lib)
}
}

Expand Down
4 changes: 2 additions & 2 deletions buildSrc/src/main/kotlin/io/spine/dependency/local/Base.kt
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@ package io.spine.dependency.local
*/
@Suppress("ConstPropertyName")
object Base {
const val version = "2.0.0-SNAPSHOT.231"
const val versionForBuildScript = "2.0.0-SNAPSHOT.231"
const val version = "2.0.0-SNAPSHOT.232"
const val versionForBuildScript = "2.0.0-SNAPSHOT.232"
const val group = Spine.group
const val artifact = "spine-base"
const val lib = "$group:$artifact:$version"
Expand Down
24 changes: 12 additions & 12 deletions dependencies.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@


# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine:spine-client:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -846,12 +846,12 @@

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:56 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:33 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine:spine-core:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.code.findbugs. **Name** : jsr305. **Version** : 3.0.2.
Expand Down Expand Up @@ -1649,12 +1649,12 @@ This report was generated on **Fri Dec 13 20:09:56 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:56 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:33 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine:spine-server:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -2508,12 +2508,12 @@ This report was generated on **Fri Dec 13 20:09:56 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:57 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:34 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine.tools:spine-testutil-client:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -3482,12 +3482,12 @@ This report was generated on **Fri Dec 13 20:09:57 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:57 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:34 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine.tools:spine-testutil-core:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -4456,12 +4456,12 @@ This report was generated on **Fri Dec 13 20:09:57 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:58 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).




# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.190`
# Dependencies of `io.spine.tools:spine-testutil-server:2.0.0-SNAPSHOT.191`

## Runtime
1. **Group** : com.google.android. **Name** : annotations. **Version** : 4.1.1.4.
Expand Down Expand Up @@ -5478,4 +5478,4 @@ This report was generated on **Fri Dec 13 20:09:58 WET 2024** using [Gradle-Lice

The dependencies distributed under several licenses, are used according their commercial-use-friendly license.

This report was generated on **Fri Dec 13 20:09:58 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
This report was generated on **Sun Dec 15 13:05:35 WET 2024** using [Gradle-License-Report plugin](https://github.com/jk1/Gradle-License-Report) by Evgeny Naumenko, licensed under [Apache 2.0 License](https://github.com/jk1/Gradle-License-Report/blob/master/LICENSE).
4 changes: 2 additions & 2 deletions pom.xml
Original file line number Diff line number Diff line change
Expand Up @@ -10,7 +10,7 @@ all modules and does not describe the project structure per-subproject.
-->
<groupId>io.spine</groupId>
<artifactId>spine-core-java</artifactId>
<version>2.0.0-SNAPSHOT.190</version>
<version>2.0.0-SNAPSHOT.191</version>

<inceptionYear>2015</inceptionYear>

Expand Down Expand Up @@ -68,7 +68,7 @@ all modules and does not describe the project structure per-subproject.
<dependency>
<groupId>io.spine</groupId>
<artifactId>spine-base</artifactId>
<version>2.0.0-SNAPSHOT.231</version>
<version>2.0.0-SNAPSHOT.232</version>
<scope>compile</scope>
</dependency>
<dependency>
Expand Down
17 changes: 14 additions & 3 deletions server/src/main/java/io/spine/server/bus/Bus.java
Original file line number Diff line number Diff line change
@@ -1,11 +1,11 @@
/*
* Copyright 2023, TeamDev. All rights reserved.
* Copyright 2024, TeamDev. All rights reserved.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
* https://www.apache.org/licenses/LICENSE-2.0
*
* Redistribution and use in source and/or binary forms, with or without
* modification, must retain the above copyright notice and the following
Expand All @@ -32,6 +32,7 @@
import com.google.protobuf.Message;
import io.grpc.stub.StreamObserver;
import io.spine.annotation.Internal;
import io.spine.base.Mistake;
import io.spine.core.Ack;
import io.spine.core.Signal;
import io.spine.core.SignalId;
Expand Down Expand Up @@ -348,13 +349,21 @@ private Optional<Ack> filter(E message) {
*
* <p>This method assumes that the given message has passed the filtering.
*
* @see #post(Signal, StreamObserver) for the public API
* @see #post(Signal, StreamObserver) the public API for posting
*/
protected abstract void dispatch(E envelope);

/**
* Posts each of the given envelopes into the bus and notifies the given observer.
*
* <p>If {@link #dispatch(SignalEnvelope) dispatching} throws a {@link Mistake} it is rethrown.
* Other types of exceptions are logged and then rethrown.
*
* <p>We treat {@link Mistake}s differently and want to void much of console output
* for this special case of exceptions.
* Please see {@link io.spine.server.model.AbstractReceptor#invoke(Object, MessageEnvelope)}
* for more details on special treatment of {@link Mistake} during dispatching.
*
* @param envelopes
* the envelopes to post
* @param observer
Expand All @@ -370,6 +379,8 @@ private void doPost(Iterable<E> envelopes, StreamObserver<Ack> observer) {
onDispatchingStarted(signalId);
try {
dispatch(envelope);
} catch (Mistake m) {
throw m;
} catch (Throwable t) {
logger().atError().withCause(t).log(() -> format(
"Unable to dispatch `%s` with ID `%s`.",
Expand Down
13 changes: 7 additions & 6 deletions server/src/main/java/io/spine/server/model/AbstractReceptor.java
Original file line number Diff line number Diff line change
Expand Up @@ -30,6 +30,7 @@
import com.google.errorprone.annotations.Immutable;
import com.google.errorprone.annotations.OverridingMethodsMustInvokeSuper;
import com.google.protobuf.Message;
import io.spine.base.Mistake;
import io.spine.base.RejectionThrowable;
import io.spine.core.Signal;
import io.spine.server.dispatch.DispatchOutcome;
Expand Down Expand Up @@ -272,8 +273,8 @@ private static ImmutableSet<Attribute<?>> discoverAttributes(Method method) {
/**
* Feeds the given {@code envelope} to the given {@code target} and returns the outcome.
*
* <p>If the target method throws {@link java.lang.Error} dispatching terminates with
* rethrowing the error.
* <p>If the target method throws {@link Mistake}, dispatching terminates with
* rethrowing it.
*
* <p>Other types of exceptions are converted to {@link io.spine.base.Error} and returned
* {@link DispatchOutcome.Builder#setError inside} the {@link DispatchOutcome}.
Expand All @@ -285,8 +286,8 @@ private static ImmutableSet<Attribute<?>> discoverAttributes(Method method) {
*/
@SuppressWarnings({
"ChainOfInstanceofChecks" /* We need to separate exceptions. */,
"ThrowInsideCatchBlockWhichIgnoresCaughtException", "ProhibitedExceptionThrown"
/* Rethrowing `Error`. See Javadoc. */
"ThrowInsideCatchBlockWhichIgnoresCaughtException",
/* Rethrowing `Mistake`. See Javadoc. */
})
@Override
public DispatchOutcome invoke(T target, E envelope) {
Expand All @@ -312,8 +313,8 @@ public DispatchOutcome invoke(T target, E envelope) {
} catch (InvocationTargetException e) {
var cause = e.getCause();
checkNotNull(cause);
if (cause instanceof Error) {
throw (Error) cause;
if (cause instanceof Mistake) {
throw (Mistake) cause;
} else if (cause instanceof RejectionThrowable) {
var success = asRejection(target, envelope, (RejectionThrowable) cause);
outcome.setSuccess(success);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -32,6 +32,7 @@ import io.kotest.matchers.shouldBe
import io.kotest.matchers.shouldNotBe
import io.spine.base.EventMessage
import io.spine.base.Identifier
import io.spine.base.Mistake
import io.spine.core.Event
import io.spine.core.Subscribe
import io.spine.protobuf.AnyPacker
Expand Down Expand Up @@ -216,17 +217,17 @@ internal class AbstractReceptorSpec {
}

@Nested inner class
`propagate instances of 'Error'` {
`propagate instances of 'Mistake'` {

private val signature = SubscriberSignature();
private val signature = SubscriberSignature()

@Test
fun `if a target throws 'java_lang_Error'`() {
val receptor = signature.classify(ErrorThrowingHandler.method("throwingError"))
fun `if a target throws 'Mistake'`() {
val receptor = signature.classify(MistakenHandler.method("throwingMistake"))
receptor.shouldBePresent()
val envelope = envelope(projectCreated())
assertThrows<Error> {
receptor.get().invoke(ErrorThrowingHandler(), envelope)
assertThrows<Mistake> {
receptor.get().invoke(MistakenHandler(), envelope)
}
}

Expand All @@ -238,21 +239,24 @@ internal class AbstractReceptorSpec {
/**
* A subscriber which throws [java.lang.Error] and [kotlin.Error] in the receptors.
*/
private class ErrorThrowingHandler : EventSubscriber {
private class MistakenHandler : EventSubscriber {

companion object {
fun method(name: String): Method {
return ModelTests.getMethod(ErrorThrowingHandler::class.java, name)
return ModelTests.getMethod(MistakenHandler::class.java, name)
}
}

@Subscribe
@Suppress("TooGenericExceptionThrown", "UNUSED_PARAMETER")
fun throwingError(e: RefProjectCreated) {
throw Error("Throwing `java.lang.Error`.")
fun throwingMistake(e: RefProjectCreated) {
throw StubMistake()
}
}

@Suppress("serial") // No need for the tests.
private class StubMistake: Mistake()

private fun envelope(eventMessage: EventMessage): EventEnvelope {
val factory = TestEventFactory.newInstance(AbstractReceptorSpec::class.java)
val event = factory.createEvent(eventMessage)
Expand Down
2 changes: 1 addition & 1 deletion version.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -29,4 +29,4 @@
*
* For versions of Spine-based dependencies, please see [io.spine.dependency.local.Spine].
*/
val versionToPublish: String by extra("2.0.0-SNAPSHOT.190")
val versionToPublish: String by extra("2.0.0-SNAPSHOT.191")

0 comments on commit d9fa60a

Please sign in to comment.