Skip to content

Commit

Permalink
cr1
Browse files Browse the repository at this point in the history
  • Loading branch information
radeusgd committed Apr 27, 2023
1 parent 6cc73f7 commit 9c6c854
Show file tree
Hide file tree
Showing 5 changed files with 36 additions and 2 deletions.
4 changes: 4 additions & 0 deletions distribution/lib/Standard/Base/0.0.0-dev/src/Panic.enso
Original file line number Diff line number Diff line change
Expand Up @@ -133,6 +133,10 @@ type Panic

This emulates the `finally` clause in Java.

If an exception occurs in the `finalizer`, it is propagated. If `action`
throws an exception and the `finalizer` also throws an exception, the
exception thrown by `finalizer` takes precedence.

> Example
Print the `Cleaning...` message regardless of if the action succeeds.
do_cleanup =
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -155,7 +155,6 @@ type Non_Unique_Primary_Key

Arguments:
- primary_key: The primary key that is not unique.
# TODO [RW] should we include `duplicate_rows` here to show example ids of rows that are not unique?
Error (primary_key : Vector Text)

## PRIVATE
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -136,6 +136,8 @@ type JDBC_Connection
Once the action is completed, the transaction is committed.
If a panic escapes from the action, the transaction is rolled-back and
closed.
If the rollback fails and panics, the panic related to the rollback will
take precedence over the original panic that caused that rollback.
run_within_transaction : Any -> Any
run_within_transaction self ~action =
self.run_without_autocommit <|
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,6 +11,10 @@
import java.util.BitSet;
import java.util.List;

/**
* A helper class used in the Upload_Spec test to purposefully interrupt a table upload in the
* middle of it by throwing an exception. It is used to test the transactionality of the upload.
*/
public class ExplodingStorage extends Storage<Long> {
private final long[] array;
private final long explodingIndex;
Expand Down
27 changes: 26 additions & 1 deletion test/Tests/src/Semantic/Error_Spec.enso
Original file line number Diff line number Diff line change
Expand Up @@ -289,7 +289,7 @@ spec =

caught_js_arr_panic . should_equal "JS array:[1, 2, 3]"

Test.specify "should allow to use with_finalizer" <|
Test.specify "should allow to use `with_finalizer`" <|
ref1 = Ref.new ""
r1 = Panic.with_finalizer (ref1.put "finalized") <|
42
Expand All @@ -311,4 +311,29 @@ spec =
r3.should_fail_with Illegal_Argument
ref3.get . should_equal "finalized"

Test.specify "should propagate any panics raised in `with_finalizer` finalization" <|
v1 = Vector.new_builder
c1 = Panic.catch Any handler=(.payload) <|
do_finalize =
v1.append 2
Panic.throw "finalizer"
do_act =
v1.append 1
42
Panic.with_finalizer do_finalize do_act
c1 . should_equal "finalizer"
v1.to_vector . should_equal [1, 2]

v2 = Vector.new_builder
c2 = Panic.catch Any handler=(.payload) <|
do_finalize =
v2.append 2
Panic.throw "finalizer"
do_act =
v2.append 1
Panic.throw "action"
Panic.with_finalizer do_finalize do_act
c2 . should_equal "finalizer"
v2.to_vector . should_equal [1, 2]

main = Test_Suite.run_main spec

0 comments on commit 9c6c854

Please sign in to comment.