Repository: nodejs/node
Pull request: sqlite: improve error handling using MaybeLocal

As per @jasnell's [suggestion](https://github.com/nodejs/node/pull/54687#discussion_r1745992906), consistently use `MaybeLocal` and avoid `Check()` and `ToLocalChecked()` entirely.

<!--
Before submitting a pull request, please read:

- the CONTRIBUTING guide at https://github.com/nodejs/node/blob/HEAD/CONTRIBUTING.md
- the commit message formatting guidelines at
  https://github.com/nodejs/node/blob/HEAD/doc/contributing/pull-requests.md#commit-message-guidelines

For code changes:
1. Include tests for any bug fixes or new features.
2. Update documentation if relevant.
3. Ensure that `make -j4 test` (UNIX), or `vcbuild test` (Windows) passes.

If you believe this PR should be highlighted in the Node.js CHANGELOG
please add the `notable-change` label.

Developer's Certificate of Origin 1.1

By making a contribution to this project, I certify that:

(a) The contribution was created in whole or in part by me and I
    have the right to submit it under the open source license
    indicated in the file; or

(b) The contribution is based upon previous work that, to the best
    of my knowledge, is covered under an appropriate open source
    license and I have the right under that license to submit that
    work with modifications, whether created in whole or in part
    by me, under the same open source license (unless I am
    permitted to submit under a different license), as indicated
    in the file; or

(c) The contribution was provided directly to me by some other
    person who certified (a), (b) or (c) and I have not modified
    it.

(d) I understand and agree that this project and the contribution
    are public and that a record of the contribution (including all
    personal information I submit with it, including my sign-off) is
    maintained indefinitely and may be redistributed consistent with
    this project or the open source license(s) involved.
-->


Changed files:
filename: src/node_sqlite.cc
patch: @@ -56,40 +56,56 @@ using v8::Value;
     }                                                                          \
   } while (0)
 
-inline Local<Object> CreateSQLiteError(Isolate* isolate, const char* message) {
-  Local<String> js_msg = String::NewFromUtf8(isolate, message).ToLocalChecked();
-  Local<Object> e = Exception::Error(js_msg)
-                        ->ToObject(isolate->GetCurrentContext())
-                        .ToLocalChecked();
-  e->Set(isolate->GetCurrentContext(),
-         OneByteString(isolate, "code"),
-         OneByteString(isolate, "ERR_SQLITE_ERROR"))
-      .Check();
+inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate,
+                                            const char* message) {
+  Local<String> js_msg;
+  Local<Object> e;
+  if (!String::NewFromUtf8(isolate, message).ToLocal(&js_msg) ||
+      !Exception::Error(js_msg)
+           ->ToObject(isolate->GetCurrentContext())
+           .ToLocal(&e) ||
+      e->Set(isolate->GetCurrentContext(),
+             OneByteString(isolate, "code"),
+             OneByteString(isolate, "ERR_SQLITE_ERROR"))
+          .IsNothing()) {
+    return MaybeLocal<Object>();
+  }
   return e;
 }
 
-inline Local<Object> CreateSQLiteError(Isolate* isolate, sqlite3* db) {
+inline MaybeLocal<Object> CreateSQLiteError(Isolate* isolate, sqlite3* db) {
   int errcode = sqlite3_extended_errcode(db);
   const char* errstr = sqlite3_errstr(errcode);
   const char* errmsg = sqlite3_errmsg(db);
-  Local<Object> e = CreateSQLiteError(isolate, errmsg);
-  e->Set(isolate->GetCurrentContext(),
-         OneByteString(isolate, "errcode"),
-         Integer::New(isolate, errcode))
-      .Check();
-  e->Set(isolate->GetCurrentContext(),
-         OneByteString(isolate, "errstr"),
-         String::NewFromUtf8(isolate, errstr).ToLocalChecked())
-      .Check();
+  Local<String> js_errmsg;
+  Local<Object> e;
+  if (!String::NewFromUtf8(isolate, errstr).ToLocal(&js_errmsg) ||
+      !CreateSQLiteError(isolate, errmsg).ToLocal(&e) ||
+      e->Set(isolate->GetCurrentContext(),
+             OneByteString(isolate, "errcode"),
+             Integer::New(isolate, errcode))
+          .IsNothing() ||
+      e->Set(isolate->GetCurrentContext(),
+             OneByteString(isolate, "errstr"),
+             js_errmsg)
+          .IsNothing()) {
+    return MaybeLocal<Object>();
+  }
   return e;
 }
 
 inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, sqlite3* db) {
-  isolate->ThrowException(CreateSQLiteError(isolate, db));
+  Local<Object> e;
+  if (CreateSQLiteError(isolate, db).ToLocal(&e)) {
+    isolate->ThrowException(e);
+  }
 }
 
 inline void THROW_ERR_SQLITE_ERROR(Isolate* isolate, const char* message) {
-  isolate->ThrowException(CreateSQLiteError(isolate, message));
+  Local<Object> e;
+  if (CreateSQLiteError(isolate, message).ToLocal(&e)) {
+    isolate->ThrowException(e);
+  }
 }
 
 DatabaseSync::DatabaseSync(Environment* env,