Skip to main content
Version: next

Error Handling

General Errors

General errors are emitted under the "error" event and do not originate from proxy handler traps.
These are standard Error Objects raised when something goes wrong within Nexos' internal logic — such as invalid method usage, listener failures, or other non-proxy runtime exceptions.

These events are useful for monitoring the general health of your application’s interaction with Nexos, especially when integrating it into complex dynamic systems.

You can listen to these errors globally through the nexo instance.

import { Nexo } from "nexos";

const nexo = new Nexo();

nexo.on("error", (error) => {
console.log("Global error from Nexo:", error.message);
});

Proxy-Specific Errors

Emits a custom ProxyError when an issue arises directly from a proxy operation.

These are special error instances thrown during lifecycle operations that Nexos manages, such as:

  • Trying to reuse the same target with different names
  • Performing invalid operations on a frozen or sealed proxy
  • Failing to define a property due to descriptor conflicts
  • Misusing a proxy that was already disconnected or replaced

Each ProxyError includes rich metadata to help you trace which proxy, name, or target was involved. You can listen to these errors globally (nexo.on) or individually on the proxy instance (proxy.on), allowing fine-grained error handling for complex systems.

import { Nexo } from "nexos";

const nexo = new Nexo();
const target = {};
const proxy = nexo.use("my-proxy", target);

proxy.on("proxy.error", (error) => {
console.warn("Proxy-level error:", error.message);
});

nexo.on("proxy.error", (error) => {
console.warn("Global proxy error:", error.message);
});

With these listeners in place, Nexos makes it easier to isolate, debug, and recover from issues that arise during dynamic proxy handling.