Skip to content
Lucent
Esc
↑↓navigate↵open
On this page

Error handling

Choose when to let Lucent show an error and when to keep going.

When a script fails, Lucent stops it and shows the Script failed dialog. You usually do not need to catch the error yourself.

If you catch an error and let the script continue, the dialog will not appear for that error. Logging it does not open the dialog either.

Let Lucent show the error

Call actions with yield* as usual:

const filesystem = require("lucent/filesystem");

module.exports = function* run() {
  yield* filesystem.writeText("notes.txt", "Run complete.");
};

If Lucent cannot write the file, such as when it lacks permission, it shows the error. Leave errors uncaught when your script cannot safely continue.

Catch an error to keep going

Use Effect.catch only when your script can continue without the failed action. Pass the action first, then what to do if it fails.

This example keeps going even if it cannot save an optional note:

const filesystem = require("lucent/filesystem");
const script = require("lucent/script");
const { Effect } = require("effect");

module.exports = function* run() {
  yield* Effect.catch(
    filesystem.writeText("notes.txt", "Run complete."),
    (error) => script.log("Could not save the note:", error),
  );
  yield* script.log("Continuing without the note.");
};

Here, the error dialog will not appear. Avoid catching errors across the whole script just to log them, since that can hide failures.

If you catch an error but still want Lucent to show it, return Effect.fail(error) from the handler.

JavaScript’s try/catch does not catch errors from actions run with yield*.

Using .pipe()

You can also write the same call with .pipe():

yield *
  filesystem
    .writeText("notes.txt", "Run complete.")
    .pipe(
      Effect.catch((error) => script.log("Could not save the note:", error)),
    );
Type preview
Open page

Last updated on September 26, 2026

Was this page helpful?