```ts try { // Check if the DB is reachable env.DB.prepare("SELECT 1").first();

    try {
      // Check if the DB is reachable
      env.DB.prepare("SELECT 1").first();
      const result = env.DB.prepare("INSERT INTO ... (...) VALUES (?, ?, ?, ?)")
        .bind()
        .run()
        .then((result: unknown) => {
          console.debug("Insertion result:", result);
        })
        .catch((error: unknown) => {
          console.error("Error inserting data:", error);
          throw error; // Rethrow to handle in the catch block
        });

      console.debug({ ... }, "logged to D1 database", { result });
    } catch (err) {
      console.error("Insertion into", { env }, "failed", err);
    }
logs
... logged to D1 database { result: Promise { <pending> } }
but it should be logging an error, because I know there's an error in one of the values I INSERT.
Was this page helpful?