Skip to content

Commit fbb3436

Browse files
Make sure we log state machine errors
1 parent 261843d commit fbb3436

2 files changed

Lines changed: 22 additions & 3 deletions

File tree

sdk-core/src/main/java23/dev/restate/sdk/core/statemachine/ffm/FfmStateMachine.java

Lines changed: 20 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030
import java.util.LinkedHashMap;
3131
import java.util.List;
3232
import java.util.Map;
33+
import org.apache.logging.log4j.Logger;
3334
import org.jspecify.annotations.Nullable;
3435

3536
/**
@@ -51,6 +52,11 @@
5152
*/
5253
public final class FfmStateMachine implements StateMachine {
5354

55+
// Same logger as the native tracing bridge, so SDK- and core-emitted lines interleave.
56+
private static final Logger LOG = NativeLogging.LOG;
57+
58+
private static final int SUSPENDED_ERROR_CODE = 599;
59+
5460
private final MemorySegment vmHandle;
5561
private final String responseContentType;
5662
private boolean freed = false;
@@ -756,10 +762,23 @@ private void verifyNotFreed() {
756762
/**
757763
* Mark the state machine as closed and throw AbortedExecutionException.
758764
*
759-
* <p>A subsequent notifyError will no-op.
765+
* <p>A subsequent notifyError will no-op. Before aborting we surface the failure the core stashed
766+
* (skipping the fetch when WARN is off, and skipping suspensions, which ride the same channel).
760767
*/
761768
private void abortAfterCoreClosed() {
762769
cachedState = InvocationState.CLOSED;
770+
if (LOG.isWarnEnabled()) {
771+
try (Arena arena = Arena.ofConfined()) {
772+
MemorySegment err = VmError.allocate(arena);
773+
SharedCoreNative.vm_take_last_vm_error(vmHandle, err);
774+
int code = VmError.code(err);
775+
// takeSliceString also frees the owned message Slice, so decode it even when not logging.
776+
String message = FfmEncoding.takeSliceString(VmError.message(err));
777+
if (code != SUSPENDED_ERROR_CODE) {
778+
LOG.warn("Invocation failed: {}", message);
779+
}
780+
}
781+
}
763782
AbortedExecutionException.sneakyThrow();
764783
}
765784

sdk-core/src/main/java23/dev/restate/sdk/core/statemachine/ffm/NativeLogging.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -52,9 +52,9 @@ final class NativeLogging {
5252
private NativeLogging() {}
5353

5454
/** Dedicated logger all native (shared-core) events are routed through. */
55-
static final String LOGGER_NAME = "dev.restate.sdk.core.StateMachine";
55+
private static final String LOGGER_NAME = "dev.restate.sdk.core.StateMachine";
5656

57-
private static final Logger LOG = LogManager.getLogger(LOGGER_NAME);
57+
static final Logger LOG = LogManager.getLogger(LOGGER_NAME);
5858

5959
/**
6060
* Optional override for the native max level, bypassing the Log4j2-derived value. Accepts {@code

0 commit comments

Comments
 (0)