[njs] FS: added back custom exception types using new public API.

Dmitry Volyntsev xeioex at nginx.com
Thu Jun 22 22:40:02 UTC 2023


details:   https://hg.nginx.org/njs/rev/aaab085e499f
branches:  
changeset: 2158:aaab085e499f
user:      Dmitry Volyntsev <xeioex at nginx.com>
date:      Wed Jun 21 16:29:45 2023 -0700
description:
FS: added back custom exception types using new public API.

In 18385a4a90ad, when rewriting FS module using public API all the
exceptions types were squashed into a single Error type. This patch
reintroduces the standard exception types back using new API.

diffstat:

 external/njs_fs_module.c |  95 ++++++++++++++++++++++++-----------------------
 src/test/njs_unit_test.c |  68 +++++++++++++++++-----------------
 test/fs/methods.t.js     |   8 ++--
 test/fs/promises_07.t.js |   2 +-
 4 files changed, 88 insertions(+), 85 deletions(-)

diffs (602 lines):

diff -r 09441c1c24ea -r aaab085e499f external/njs_fs_module.c
--- a/external/njs_fs_module.c	Wed Jun 21 16:17:42 2023 -0700
+++ b/external/njs_fs_module.c	Wed Jun 21 16:29:45 2023 -0700
@@ -1433,7 +1433,7 @@ njs_fs_access(njs_vm_t *vm, njs_value_t 
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -1449,7 +1449,7 @@ njs_fs_access(njs_vm_t *vm, njs_value_t 
         md = F_OK;
 
     } else {
-        njs_vm_error(vm, "\"mode\" must be a number");
+        njs_vm_type_error(vm, "\"mode\" must be a number");
         return NJS_ERROR;
     }
 
@@ -1587,7 +1587,7 @@ njs_fs_mkdir(njs_vm_t *vm, njs_value_t *
     if (njs_slow_path(calltype == NJS_FS_CALLBACK)) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -1604,8 +1604,8 @@ njs_fs_mkdir(njs_vm_t *vm, njs_value_t *
 
     } else if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type"
-                         "(a number or object required)");
+            njs_vm_type_error(vm, "Unknown options type"
+                             "(a number or object required)");
             return NJS_ERROR;
         }
 
@@ -1669,7 +1669,8 @@ njs_fs_read(njs_vm_t *vm, njs_value_t *a
     }
 
     if (njs_slow_path(offset < 0 || (size_t) offset > data.length)) {
-        njs_vm_error(vm, "offset is out of range (must be <= %z)", data.length);
+        njs_vm_range_error(vm, "offset is out of range (must be <= %z)",
+                           data.length);
         return NJS_ERROR;
     }
 
@@ -1685,8 +1686,8 @@ njs_fs_read(njs_vm_t *vm, njs_value_t *a
         }
 
         if (njs_slow_path(length < 0 || (size_t) length > data.length)) {
-            njs_vm_error(vm, "length is out of range (must be <= %z)",
-                         data.length);
+            njs_vm_range_error(vm, "length is out of range (must be <= %z)",
+                               data.length);
             return NJS_ERROR;
         }
 
@@ -1760,7 +1761,7 @@ njs_fs_read_file(njs_vm_t *vm, njs_value
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -1777,8 +1778,8 @@ njs_fs_read_file(njs_vm_t *vm, njs_value
 
     } else if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                         "(a string or object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                              "(a string or object required)");
             return NJS_ERROR;
         }
 
@@ -1880,7 +1881,7 @@ njs_fs_readdir(njs_vm_t *vm, njs_value_t
     if (njs_slow_path(calltype == NJS_FS_CALLBACK)) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
         if (options == callback) {
@@ -1896,8 +1897,8 @@ njs_fs_readdir(njs_vm_t *vm, njs_value_t
 
     } else if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                         "(a string or object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                             "(a string or object required)");
             return NJS_ERROR;
         }
 
@@ -2022,7 +2023,7 @@ njs_fs_realpath(njs_vm_t *vm, njs_value_
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -2038,8 +2039,8 @@ njs_fs_realpath(njs_vm_t *vm, njs_value_
 
     } else if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                           "(a string or object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                              "(a string or object required)");
             return NJS_ERROR;
         }
 
@@ -2101,7 +2102,7 @@ njs_fs_rename(njs_vm_t *vm, njs_value_t 
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, 3);
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
     }
@@ -2152,7 +2153,7 @@ njs_fs_rmdir(njs_vm_t *vm, njs_value_t *
     if (njs_slow_path(calltype == NJS_FS_CALLBACK)) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
         if (options == callback) {
@@ -2164,8 +2165,8 @@ njs_fs_rmdir(njs_vm_t *vm, njs_value_t *
 
     if (njs_slow_path(!njs_value_is_undefined(options))) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                           "(an object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                              "(an object required)");
             return NJS_ERROR;
         }
 
@@ -2229,7 +2230,7 @@ njs_fs_stat(njs_vm_t *vm, njs_value_t *a
     if (njs_slow_path(calltype == NJS_FS_CALLBACK)) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 3));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -2242,14 +2243,14 @@ njs_fs_stat(njs_vm_t *vm, njs_value_t *a
 
     if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                           "(an object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                              "(an object required)");
             return NJS_ERROR;
         }
 
         value = njs_vm_object_prop(vm, options, &string_bigint, &result);
         if (value != NULL && njs_value_bool(value)) {
-            njs_vm_error(vm, "\"bigint\" is not supported");
+            njs_vm_type_error(vm, "\"bigint\" is not supported");
             return NJS_ERROR;
         }
 
@@ -2328,7 +2329,7 @@ njs_fs_symlink(njs_vm_t *vm, njs_value_t
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 4));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -2340,7 +2341,7 @@ njs_fs_symlink(njs_vm_t *vm, njs_value_t
     if (njs_slow_path(!njs_value_is_undefined(type)
                       && !njs_value_is_string(type)))
     {
-        njs_vm_error(vm, "\"type\" must be a string");
+        njs_vm_type_error(vm, "\"type\" must be a string");
         return NJS_ERROR;
     }
 
@@ -2380,7 +2381,7 @@ njs_fs_unlink(njs_vm_t *vm, njs_value_t 
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, 2);
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
     }
@@ -2474,8 +2475,8 @@ njs_fs_write(njs_vm_t *vm, njs_value_t *
     }
 
     if (njs_slow_path(offset < 0 || (size_t) offset > data.length)) {
-        njs_vm_error(vm, "offset is out of range (must be <= %z)",
-                     data.length);
+        njs_vm_range_error(vm, "offset is out of range (must be <= %z)",
+                           data.length);
         return NJS_ERROR;
     }
 
@@ -2491,8 +2492,8 @@ njs_fs_write(njs_vm_t *vm, njs_value_t *
         }
 
         if (njs_slow_path(length < 0 || (size_t) length > data.length)) {
-            njs_vm_error(vm, "length is out of range (must be <= %z)",
-                         data.length);
+            njs_vm_range_error(vm, "length is out of range (must be <= %z)",
+                               data.length);
             return NJS_ERROR;
         }
 
@@ -2577,7 +2578,7 @@ njs_fs_write_file(njs_vm_t *vm, njs_valu
     if (calltype == NJS_FS_CALLBACK) {
         callback = njs_arg(args, nargs, njs_min(nargs - 1, 4));
         if (!njs_value_is_function(callback)) {
-            njs_vm_error(vm, "\"callback\" must be a function");
+            njs_vm_type_error(vm, "\"callback\" must be a function");
             return NJS_ERROR;
         }
 
@@ -2595,8 +2596,8 @@ njs_fs_write_file(njs_vm_t *vm, njs_valu
 
     } else if (!njs_value_is_undefined(options)) {
         if (!njs_value_is_object(options)) {
-            njs_vm_error(vm, "Unknown options type "
-                         "(a string or object required)");
+            njs_vm_type_error(vm, "Unknown options type "
+                              "(a string or object required)");
             return NJS_ERROR;
         }
 
@@ -2781,7 +2782,7 @@ njs_fs_make_path(njs_vm_t *vm, char *pat
         }
 
         if (njs_slow_path((p - path) > NJS_MAX_PATH)) {
-            njs_vm_error(vm, "too large path");
+            njs_vm_internal_error(vm, "too large path");
             return NJS_ERROR;
         }
 
@@ -3064,18 +3065,19 @@ njs_fs_path(njs_vm_t *vm, char storage[N
         }
 
     } else {
-        njs_vm_error(vm, "\"%s\" must be a string or Buffer", prop_name);
+        njs_vm_type_error(vm, "\"%s\" must be a string or Buffer", prop_name);
         return NULL;
     }
 
     if (njs_slow_path(str.length > NJS_MAX_PATH - 1)) {
-        njs_vm_error(vm, "\"%s\" is too long >= %d", prop_name, NJS_MAX_PATH);
+        njs_vm_internal_error(vm, "\"%s\" is too long >= %d", prop_name,
+                              NJS_MAX_PATH);
         return NULL;
     }
 
     if (njs_slow_path(memchr(str.start, '\0', str.length) != 0)) {
-        njs_vm_error(vm, "\"%s\" must be a Buffer without null bytes",
-                       prop_name);
+        njs_vm_type_error(vm, "\"%s\" must be a Buffer without null bytes",
+                          prop_name);
         return NULL;
     }
 
@@ -3110,7 +3112,7 @@ njs_fs_flags(njs_vm_t *vm, njs_value_t *
         }
     }
 
-    njs_vm_error(vm, "Unknown file open flags: \"%V\"", &flags);
+    njs_vm_type_error(vm, "Unknown file open flags: \"%V\"", &flags);
 
     return -1;
 }
@@ -3301,7 +3303,7 @@ njs_fs_result(njs_vm_t *vm, njs_opaque_v
         return NJS_OK;
 
     default:
-        njs_vm_error(vm, "invalid calltype");
+        njs_vm_internal_error(vm, "invalid calltype");
 
         return NJS_ERROR;
     }
@@ -3339,7 +3341,7 @@ njs_fs_dirent_constructor(njs_vm_t *vm, 
     njs_uint_t nargs, njs_index_t unused, njs_value_t *retval)
 {
     if (njs_slow_path(!njs_vm_constructor(vm))) {
-        njs_vm_error(vm, "the Dirent constructor must be called with new");
+        njs_vm_type_error(vm, "the Dirent constructor must be called with new");
         return NJS_ERROR;
     }
 
@@ -3365,7 +3367,8 @@ njs_fs_dirent_test(njs_vm_t *vm, njs_val
     if (njs_slow_path(njs_value_is_number(type)
                       && (njs_value_number(type) == NJS_DT_INVALID)))
     {
-        njs_vm_error(vm, "dentry type is not supported on this platform");
+        njs_vm_internal_error(vm, "dentry type is not supported on this "
+                              "platform");
         return NJS_ERROR;
     }
 
@@ -3603,7 +3606,7 @@ njs_fs_filehandle_close(njs_vm_t *vm, nj
 
     fh = njs_vm_external(vm, njs_fs_filehandle_proto_id, njs_argument(args, 0));
     if (njs_slow_path(fh == NULL)) {
-        njs_vm_error(vm, "\"this\" is not a filehandle object");
+        njs_vm_type_error(vm, "\"this\" is not a filehandle object");
         return NJS_ERROR;
     }
 
@@ -3629,7 +3632,7 @@ njs_fs_filehandle_value_of(njs_vm_t *vm,
 
     fh = njs_vm_external(vm, njs_fs_filehandle_proto_id, njs_argument(args, 0));
     if (njs_slow_path(fh == NULL)) {
-        njs_vm_error(vm, "\"this\" is not a filehandle object");
+        njs_vm_type_error(vm, "\"this\" is not a filehandle object");
         return NJS_ERROR;
     }
 
diff -r 09441c1c24ea -r aaab085e499f src/test/njs_unit_test.c
--- a/src/test/njs_unit_test.c	Wed Jun 21 16:17:42 2023 -0700
+++ b/src/test/njs_unit_test.c	Wed Jun 21 16:29:45 2023 -0700
@@ -20043,32 +20043,32 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.readFile()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "var path = Buffer.from('/broken'); path[3] = 0;"
               "fs.readFile(path)"),
-      njs_str("Error: \"path\" must be a Buffer without null bytes") },
+      njs_str("TypeError: \"path\" must be a Buffer without null bytes") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path', 'utf8')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path', {flag:'xx'})"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path', {flag:'xx'}, 1)"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path', {flag:'xx'}, function () {})"),
-      njs_str("Error: Unknown file open flags: \"xx\"") },
+      njs_str("TypeError: Unknown file open flags: \"xx\"") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFile('/njs_unknown_path', {encoding:'ascii'}, function () {})"),
@@ -20082,15 +20082,15 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.readFileSync()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFileSync({})"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFileSync('/njs_unknown_path', {flag:'xx'})"),
-      njs_str("Error: Unknown file open flags: \"xx\"") },
+      njs_str("TypeError: Unknown file open flags: \"xx\"") },
 
     { njs_str("var fs = require('fs');"
               "fs.readFileSync(Buffer.from('/njs_unknown_path'), {encoding:'ascii'})"),
@@ -20102,38 +20102,38 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.readFileSync('/njs_unknown_path', true)"),
-      njs_str("Error: Unknown options type (a string or object required)") },
+      njs_str("TypeError: Unknown options type (a string or object required)") },
 
 
     /* require('fs').writeFile() */
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile({}, '', function () {})"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '', undefined)"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '', 'utf8')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '', {flag:'xx'}, function () {})"),
-      njs_str("Error: Unknown file open flags: \"xx\"") },
+      njs_str("TypeError: Unknown file open flags: \"xx\"") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '', {encoding:'ascii'}, function () {})"),
@@ -20145,21 +20145,21 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.writeFile('/njs_unknown_path', '', true, function () {})"),
-      njs_str("Error: Unknown options type (a string or object required)") },
+      njs_str("TypeError: Unknown options type (a string or object required)") },
 
     /* require('fs').writeFileSync() */
 
     { njs_str("var fs = require('fs');"
               "fs.writeFileSync()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFileSync({}, '')"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFileSync('/njs_unknown_path', '', {flag:'xx'})"),
-      njs_str("Error: Unknown file open flags: \"xx\"") },
+      njs_str("TypeError: Unknown file open flags: \"xx\"") },
 
     { njs_str("var fs = require('fs');"
               "fs.writeFileSync('/njs_unknown_path', '', {encoding:'ascii'})"),
@@ -20171,17 +20171,17 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.writeFileSync('/njs_unknown_path', '', true)"),
-      njs_str("Error: Unknown options type (a string or object required)") },
+      njs_str("TypeError: Unknown options type (a string or object required)") },
 
     /* require('fs').renameSync() */
 
     { njs_str("var fs = require('fs');"
               "fs.renameSync()"),
-      njs_str("Error: \"oldPath\" must be a string or Buffer") },
+      njs_str("TypeError: \"oldPath\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.renameSync('/njs_unknown_path')"),
-      njs_str("Error: \"newPath\" must be a string or Buffer") },
+      njs_str("TypeError: \"newPath\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "[undefined, null, false, NaN, Symbol(), {}, Object('/njs_unknown_path')]"
@@ -20201,29 +20201,29 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.access()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.access('/njs_unknown_path')"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.access('/njs_unknown_path', fs.constants.F_OK)"),
-      njs_str("Error: \"callback\" must be a function") },
+      njs_str("TypeError: \"callback\" must be a function") },
 
     { njs_str("var fs = require('fs');"
               "fs.access('/njs_unknown_path', 'fail', function () {})"),
-      njs_str("Error: \"mode\" must be a number") },
+      njs_str("TypeError: \"mode\" must be a number") },
 
     /* require('fs').accessSync() */
 
     { njs_str("var fs = require('fs');"
               "fs.accessSync()"),
-      njs_str("Error: \"path\" must be a string or Buffer") },
+      njs_str("TypeError: \"path\" must be a string or Buffer") },
 
     { njs_str("var fs = require('fs');"
               "fs.accessSync('/njs_unknown_path', 'fail')"),
-      njs_str("Error: \"mode\" must be a number") },
+      njs_str("TypeError: \"mode\" must be a number") },
 
     { njs_str("var "
               "fs = require('fs'),"
@@ -20308,7 +20308,7 @@ static njs_unit_test_t  njs_fs_module_te
 
     { njs_str("var fs = require('fs');"
               "fs.Dirent('file', 123)"),
-      njs_str("Error: the Dirent constructor must be called with new") },
+      njs_str("TypeError: the Dirent constructor must be called with new") },
 
     { njs_str("var fs = require('fs');"
               "var e = new fs.Dirent('file', 123); [e.name, e.type]"),
@@ -22848,12 +22848,12 @@ static njs_unit_test_t  njs_shared_test[
       njs_str("37") },
 
     { njs_str("var fs = require('fs'); fs.readFileSync()"),
-      njs_str("Error: \"path\" must be a string or Buffer\n"
+      njs_str("TypeError: \"path\" must be a string or Buffer\n"
               "    at fs.readFileSync (native)\n"
               "    at main (:1)\n") },
 
     { njs_str("import fs from 'fs'; fs.readFileSync()"),
-      njs_str("Error: \"path\" must be a string or Buffer\n"
+      njs_str("TypeError: \"path\" must be a string or Buffer\n"
               "    at fs.readFileSync (native)\n"
               "    at main (:1)\n") },
 
diff -r 09441c1c24ea -r aaab085e499f test/fs/methods.t.js
--- a/test/fs/methods.t.js	Wed Jun 21 16:17:42 2023 -0700
+++ b/test/fs/methods.t.js	Wed Jun 21 16:29:45 2023 -0700
@@ -898,7 +898,7 @@ let read_tests = () => [
         content: "ABC",
         read: [ [0, 5], ],
         check: (err, params) => {
-            if (err.message.indexOf('is out of range') == -1) {
+            if (!(err instanceof RangeError)) {
                 throw Error(`${err.message} unexpected exception`);
             }
 
@@ -910,7 +910,7 @@ let read_tests = () => [
         content: "ABC",
         read: [ [2, 3], ],
         check: (err, params) => {
-            if (err.message.indexOf('is out of range') == -1) {
+            if (!(err instanceof RangeError)) {
                 throw Error(`${err.message} unexpected exception`);
             }
 
@@ -1104,7 +1104,7 @@ let write_tests = () => [
         args: ["@", 'w'],
         write: [ [Buffer.from("__ABC__"), 8] ],
         check: (err, params) => {
-            if (err.message.indexOf('is out of range') == -1) {
+            if (!(err instanceof RangeError)) {
                 throw Error(`${err.message} unexpected exception`);
             }
 
@@ -1116,7 +1116,7 @@ let write_tests = () => [
         args: ["@", 'w'],
         write: [ [Buffer.from("__ABC__"), 7, 1] ],
         check: (err, params) => {
-            if (err.message.indexOf('is out of range') == -1) {
+            if (!(err instanceof RangeError)) {
                 throw Error(`${err.message} unexpected exception`);
             }
 
diff -r 09441c1c24ea -r aaab085e499f test/fs/promises_07.t.js
--- a/test/fs/promises_07.t.js	Wed Jun 21 16:17:42 2023 -0700
+++ b/test/fs/promises_07.t.js	Wed Jun 21 16:29:45 2023 -0700
@@ -26,7 +26,7 @@ var match = (entry) => {
             return false;
         }
     } catch (e) {
-        if (e.message == 'dentry type is not supported on this platform') {
+        if (e instanceof InternalError) {
             return true;
         }
 


More information about the nginx-devel mailing list