Skip to content

Rift v0.2.5 — Exception Handling Support

Latest

Choose a tag to compare

@singlephon singlephon released this 06 Aug 19:27
· 1 commit to master since this release

What's New

Rift now supports full exception handling via the new exception(error) hook directly inside your riftjs components. This powerful addition makes error control much more intuitive and customizable on the frontend, mirroring but extending the backend capabilities of Livewire's exception() method.

Purpose

With this release, you can now intercept, suppress, or modify how your component behaves when an error occurs, giving you total control over the flow of your Rift component logic.

How It Works

A new lifecycle hook has been introduced:

exception(error) {
    // Handle error
}

This method is triggered whenever an internal error is thrown within a riftjs component.

It works similarly to Livewire's exception() hook, but is applied to the frontend mirror of your component. As a reminder:

  • riftphp – backend (Livewire-powered)
  • riftjs – frontend (component mirror, with extended interactivity)

Usage Examples

1. Catch specific error and suppress it

exception(error) {
    if (error instanceof MemberNotFoundError){
        console.warn('[Suppressed]', error.message);
        return false; // Do not throw further
    }
}
  1. Catch all generic JS errors
exception(error) {
    if (error instanceof Error) {
        console.error('Caught JS error:', error);
        return false;
    }
}
  1. Globally suppress all exceptions
exception(error) {
    return false;
}

By returning false, you prevent the error from being thrown or logged.
If you return true (or omit the return entirely), the error will bubble up as usual.

Technical Notes

  • Works for both runtime exceptions (throw new Error(...)) and framework-level errors like:
    • ComponentNotFoundError
    • PropertyNotFoundError
    • MemberNotFoundError
    • …
  • Fully extendable and composable with your component logic.
  • Can be used for:
    • Graceful degradation
    • Debug-friendly output
    • Dynamic fallback behavior
    • Silent failure in production
  • Inspired by Livewire v3’s backend hook, but now you get frontend control too.

Behind the Scenes

Under the hood:

  • Proxybased interception (get, set) now funnels errors into this unified hook.
  • A base RiftError class has been introduced.
  • All internal Rift exceptions now extend from it.
  • A unified MemberNotFoundError has replaced separated MethodNotFoundError and PropertyNotFoundError for simpler debugging.

Summary

  • Centralized exception control ✅
  • Cleaner debug workflow ✅
  • Full parity with Livewire’s backend handling ✅
  • No more uncaught or mystery errors in the console ✅

If you're building interactive components in Rift, this hook gives you a first-class error layer to tame unexpected behavior without cluttering your methods.