# manual-assert

Prefer assertions over conditional panics

An `if` branch whose only operation is `panic` expresses an assertion through manual control flow.
Instead, you SHOULD use `assert` with the opposite condition.

Wrap a computed message in a zero-argument lambda so it is evaluated only after failure.

- Category: style
- Level: warning
- Fix: none
- Scope: module

## Reported

```ds title="main.ds"
import { panic } from "destack:error";

function divide(value: int32, divisor: int32): int32 {
    if (divisor == 0) {
        panic("divisor must not be zero");
    }

    return value / divisor;
}
```

## Accepted

```ds title="main.ds"
import { assert } from "destack:assert";

function divide(value: int32, divisor: int32): int32 {
    assert(divisor != 0, "divisor must not be zero");

    return value / divisor;
}
```

## Prior art

- [Clippy · manual_assert](https://rust-lang.github.io/rust-clippy/master/index.html#manual_assert)

[language/linter/src/rules/style/manual_assert.rs:6](https://github.com/destack-sh/destack/blob/main/language/linter/src/rules/style/manual_assert.rs#L6)
