Skip to content

Error is thrown when compensation is :noop #44

@kokjinsam

Description

@kokjinsam

Example

Sage.new()
|> Sage.run(:step1, &fun_one/2)
|> Sage.run_async(:step2, &fun_two/2, :noop)
|> Sage.run(:step3, &fun_three/2)
|> Sage.transaction(Repo, args)

Expected Behavior

When step3 returns {:error, reason}, operations in step1 and step3 should be rolled back and :noop for step2.

Current Behavior

The following error is thrown:

** (BadFunctionError) expected a function, got: :noop
    (sage) lib/sage/executor.ex:299: Sage.Executor.apply_compensation_fun/5
    (sage) lib/sage/executor.ex:271: Sage.Executor.safe_apply_compensation_fun/5
    (sage) lib/sage/executor.ex:264: Sage.Executor.execute_compensation/2
    (sage) lib/sage/executor.ex:240: Sage.Executor.execute_compensations/4
    (sage) lib/sage/executor.ex:29: Sage.Executor.execute/2
    (sage) lib/sage.ex:422: anonymous fn/3 in Sage.transaction/3
    (ecto_sql) lib/ecto/adapters/sql.ex:898: anonymous fn/3 in Ecto.Adapters.SQL.checkout_or_transaction/4
    (db_connection) lib/db_connection.ex:1415: DBConnection.run_transaction/4
    (sage) lib/sage.ex:421: Sage.transaction/3

Why this is a problem?

This behavior will become an issue if you're composing multiple sages.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions