Skip to content

Commit e47c123

Browse files
author
Andrei Constantinescu
authored
feat: Add isCleanReject to the Error module, align reject code order with spec and improve comments (#401)
* Add isCleanReject. * Run validate. * Run format. * Swap ordering. * Add Changelog entry. * Better comments for ErrorCode variants. * Update Changelog.
1 parent 95dcf60 commit e47c123

File tree

3 files changed

+14
-5
lines changed

3 files changed

+14
-5
lines changed

Changelog.md

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
## Next
22

3+
* Add `isCleanReject` to `Error`, align reject code order with IC interface specification and improve comments (#401).
34
* internal: updates `matchers` dev-dependency (#394).
45
* Add `PriorityQueue` (#392).
56
* Add support for Weak references (#388).

src/Error.mo

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -17,14 +17,14 @@ module {
1717
/// #system_fatal;
1818
/// // Transient error.
1919
/// #system_transient;
20-
/// // Response unknown due to missed deadline.
21-
/// #system_unknown;
2220
/// // Destination invalid.
2321
/// #destination_invalid;
22+
/// // Canister error (e.g., trap, no response).
23+
/// #canister_error;
2424
/// // Explicit reject by canister code.
2525
/// #canister_reject;
26-
/// // Canister trapped.
27-
/// #canister_error;
26+
/// // Response unknown; system stopped waiting for it (e.g., timed out, or system under high load).
27+
/// #system_unknown;
2828
/// // Future error code (with unrecognized numeric code).
2929
/// #future : Nat32;
3030
/// // Error issuing inter-canister call
@@ -66,6 +66,13 @@ module {
6666
/// ```
6767
public let message : (error : Error) -> Text = Prim.errorMessage;
6868

69+
/// Checks if the error is a clean reject.
70+
/// A clean reject means that there must be no state changes on the callee side.
71+
public func isCleanReject(error : Error) : Bool = switch (code error) {
72+
case (#system_fatal or #system_transient or #destination_invalid or #call_error _) true;
73+
case _ false
74+
};
75+
6976
/// Returns whether retrying to send a message may result in success.
7077
///
7178
/// Example:
@@ -92,7 +99,7 @@ module {
9299
///
93100
/// ```
94101
public func isRetryPossible(error : Error) : Bool = switch (code error) {
95-
case (#system_unknown or #system_transient) true;
102+
case (#system_transient or #system_unknown) true;
96103
case _ false
97104
};
98105

validation/api/api.lock.json

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -131,6 +131,7 @@
131131
"public let code : (error : Error) -> ErrorCode",
132132
"public type Error",
133133
"public type ErrorCode",
134+
"public func isCleanReject(error : Error) : Bool",
134135
"public func isRetryPossible(error : Error) : Bool",
135136
"public let message : (error : Error) -> Text",
136137
"public let reject : (message : Text) -> Error"

0 commit comments

Comments
 (0)