Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions src/main/java/com/github/sttk/sabi/AsyncGroup.java
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,9 @@ record RunnerFailed() {}
*/
record RunnerInterrupted() {}

/** Represents an unexpected {@link RuntimeException} that occurred. */
record RuntimeExceptionOccurred() {}

/**
* Adds a {@link Runner} to this group for asynchronous execution. The added runner will be
* executed in a separate thread.
Expand Down
12 changes: 10 additions & 2 deletions src/main/java/com/github/sttk/sabi/DataHub.java
Original file line number Diff line number Diff line change
Expand Up @@ -193,8 +193,10 @@ public <D> void run(Logic<D> logic) throws Err {
try {
this.begin();
logic.run(data);
} catch (Err | RuntimeException e) {
} catch (Err e) {
throw e;
} catch (RuntimeException e) {
throw new Err(new RuntimeExceptionOccurred(), e);
} finally {
this.end();
}
Expand Down Expand Up @@ -226,7 +228,13 @@ public <D> void txn(Logic<D> logic) throws Err {
this.begin();
logic.run(data);
this.commit();
} catch (Err | RuntimeException | Error e) {
} catch (Err e) {
this.rollback();
throw e;
} catch (RuntimeException e) {
this.rollback();
throw new Err(new RuntimeExceptionOccurred(), e);
} catch (Error e) {
this.rollback();
throw e;
} finally {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -27,8 +27,10 @@ public void add(final Runner runner) {
() -> {
try {
runner.run();
} catch (Err | RuntimeException e) {
} catch (Err e) {
addErr(name, e);
} catch (RuntimeException e) {
addErr(name, new Err(new AsyncGroup.RuntimeExceptionOccurred(), e));
}
});

Expand All @@ -42,8 +44,7 @@ public void add(final Runner runner) {
}
}

synchronized void addErr(String name, Exception e) {
var err = (e instanceof Err) ? Err.class.cast(e) : new Err(new RunnerFailed(), e);
synchronized void addErr(String name, Err err) {
var ent = new ErrEntry(name, err);

if (this.errLast == null) {
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/com/github/sttk/sabi/internal/DataHubInner.java
Original file line number Diff line number Diff line change
Expand Up @@ -190,8 +190,8 @@ public <C extends DataConn> C getDataConn(String name, Class<C> cls) throws Err
DataConn conn;
try {
conn = dsPtr.ds.createDataConn();
} catch (Err | RuntimeException e) {
throw new Err(new DataHub.FailToCreateDataConn(name, cls.getName()));
} catch (Exception e) {
throw new Err(new DataHub.FailToCreateDataConn(name, cls.getName()), e);
}
if (conn == null) {
throw new Err(new DataHub.CreatedDataConnIsNull(name, cls.getName()));
Expand Down
4 changes: 4 additions & 0 deletions src/main/java/com/github/sttk/sabi/internal/DataSrcList.java
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
package com.github.sttk.sabi.internal;

import com.github.sttk.errs.Err;
import com.github.sttk.sabi.DataHub;
import com.github.sttk.sabi.DataSrc;
import java.util.HashMap;
import java.util.Map;
Expand Down Expand Up @@ -139,6 +140,9 @@ Map<String, Err> setupDataSrcs() {
} catch (Err err) {
errMap.put(ptr.name, err);
break;
} catch (RuntimeException e) {
errMap.put(ptr.name, new Err(new DataHub.RuntimeExceptionOccurred(), e));
break;
}
ptr = ptr.next;
}
Expand Down