# Is there a better way to run a check for a falliable shortcut and fall back to a normal way?

**URL:** <https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209>\
**Category:** Help\
**Tags:** language\
**Created:** [August 12, 2026, 7:42pm UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209 "2026-08-12T19:42:22Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![rosew0od](https://ziggit.dev/user_avatar/ziggit.dev/rosew0od/32/7663_2.png) [@rosew0od](https://ziggit.dev/u/rosew0od)\
**Post date:** [August 12, 2026, 7:42pm UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209/1 "2026-08-12T19:42:22Z")

</div>

This seems unreasonably terse

```zig
_ = blk: {
    if (hasShortcut()) |context|
        return canFail(context) catch break :blk {};
}

return try normalWay();

```

---

<div class="post-metadata">

**Author:** ![svin67](https://ziggit.dev/letter_avatar_proxy/v4/letter/s/b5ac83/32.png) [@svin67](https://ziggit.dev/u/svin67)\
**Post date:** [August 12, 2026, 8:00pm UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209/2 "2026-08-12T20:00:10Z")

</div>

Doesn’t the `return` make the `break` useless here? That whole line looks really strange imo.

If I understood what you want correctly, this is what I would do (with braces for clarity):

```zig
if (hasShortcut()) |context| {
    if (canFail(context)) |result| {
        return result;
    } else |_| {}
}

return try normalWay();

```

---

<div class="post-metadata">

**Author:** ![jmstevers](https://ziggit.dev/user_avatar/ziggit.dev/jmstevers/32/9230_2.png) [@jmstevers](https://ziggit.dev/u/jmstevers)\
**Post date:** [August 12, 2026, 8:01pm UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209/3 "2026-08-12T20:01:22Z")

</div>

Two alternatives:

```zig
const context = hasShortcut() orelse return try normalWay();
return canFail(context) catch try normalWay();

```

```zig
fn shortcut() !T {
	const context = hasShortcut() orelse return error.NoShortcut;
	return try canFail(context);
}
...
return shortcut() catch try normalWay();

```

---

<div class="post-metadata">

**Author:** ![hachanuy](https://ziggit.dev/user_avatar/ziggit.dev/hachanuy/32/3619_2.png) [@hachanuy](https://ziggit.dev/u/hachanuy)\
**Post date:** [August 13, 2026, 8:38am UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209/4 "2026-08-13T08:38:12Z")

</div>

```zig
if (hasShortcut()) |context| if (canFail(context)) |result| 
    return result
else |_| {};

return try normalWay();

```

---

<div class="post-metadata">

**Author:** ![abdullah-b-al](https://ziggit.dev/user_avatar/ziggit.dev/abdullah-b-al/32/4601_2.png) [@abdullah-b-al](https://ziggit.dev/u/abdullah-b-al)\
**Post date:** [August 13, 2026, 10:47am UTC](https://ziggit.dev/t/is-there-a-better-way-to-run-a-check-for-a-falliable-shortcut-and-fall-back-to-a-normal-way/17209/5 "2026-08-13T10:47:53Z")

</div>

A bit verbose, but I like finding excuses to use labeled switches:

```zig
const state: union(enum) {
    start,
    can_fail: Context,
    normal,
} = .start;

return branch: switch (state) {
    .start => {
        continue :branch if (hasShortcut()) |ctx|
            .{ .can_fail = ctx }
        else
            .normal;
    },
    .can_fail => |ctx| canFail(ctx) catch continue :branch .normal,
    .normal => try normalWay(),
};

```
