Skip to content
This repository was archived by the owner on Jun 17, 2026. It is now read-only.

Commit c9a0816

Browse files
authored
feat: add Error.isRetryPossible, a predicate for non-fatal messaging errors (#692)
This predicate categorises `Error`s based on the potential success when resending the message. It _doesn't_ consider semantic issues like idempotence or such.
1 parent 9709055 commit c9a0816

2 files changed

Lines changed: 20 additions & 1 deletion

File tree

‎CHANGELOG.md‎

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,7 @@
1+
## 0.14.3
2+
3+
* Added `isRetryPossible : Error -> Bool` to `Error` (#692).
4+
15
## 0.14.2
26

37
(nothing)

‎src/Error.mo‎

Lines changed: 16 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,11 +60,26 @@ module {
6060
/// Example:
6161
/// ```motoko
6262
/// import Error "mo:base/Error";
63-
/// import Debug "mo:base/Debug";
6463
///
6564
/// let error = Error.reject("Example error");
6665
/// Error.message(error) // "Example error"
6766
/// ```
6867
public let message : (error : Error) -> Text = Prim.errorMessage;
6968

69+
/// Returns whether retrying to send a message may result in success.
70+
///
71+
/// Example:
72+
/// ```motoko
73+
/// import { message; isRetryPossible } "mo:base/Error";
74+
/// import { print } "mo:base/Debug";
75+
///
76+
/// try await (with timeout = 3) Actor.call(arg)
77+
/// catch e { if (isRetryPossible e) print(message e) }
78+
/// ```
79+
public func isRetryPossible(error : Error) : Bool =
80+
switch (code error) {
81+
case (#system_unknown or #system_transient) true;
82+
case _ false
83+
};
84+
7085
}

0 commit comments

Comments
 (0)