@@ -997,11 +997,18 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
997
997
Maybe<URL> resolved = ResolveExportsTarget (env, pjson_url,
998
998
target_item, subpath, pkg_subpath, base);
999
999
if (resolved.IsNothing ()) {
1000
- CHECK (try_catch.HasCaught () && !try_catch.Exception ().IsEmpty ());
1001
- auto e = try_catch.Exception ()->ToObject (context).ToLocalChecked ();
1002
- auto code = e->Get (context, env->code_string ()).ToLocalChecked ();
1003
- Utf8Value code_utf8 (env->isolate (),
1004
- code->ToString (context).ToLocalChecked ());
1000
+ CHECK (try_catch.HasCaught ());
1001
+ if (try_catch.Exception ().IsEmpty ()) return Nothing<URL>();
1002
+ Local<Object> e;
1003
+ if (!try_catch.Exception ()->ToObject (context).ToLocal (&e))
1004
+ return Nothing<URL>();
1005
+ Local<Value> code;
1006
+ if (!e->Get (context, env->code_string ()).ToLocal (&code))
1007
+ return Nothing<URL>();
1008
+ Local<String> code_string;
1009
+ if (!code->ToString (context).ToLocal (&code_string))
1010
+ return Nothing<URL>();
1011
+ Utf8Value code_utf8 (env->isolate (), code_string);
1005
1012
if (strcmp (*code_utf8, " ERR_PACKAGE_PATH_NOT_EXPORTED" ) == 0 ||
1006
1013
strcmp (*code_utf8, " ERR_INVALID_PACKAGE_TARGET" ) == 0 ) {
1007
1014
continue ;
@@ -1046,11 +1053,18 @@ Maybe<URL> ResolveExportsTarget(Environment* env,
1046
1053
Maybe<URL> resolved = ResolveExportsTarget (env, pjson_url,
1047
1054
conditionalTarget, subpath, pkg_subpath, base);
1048
1055
if (resolved.IsNothing ()) {
1049
- CHECK (try_catch.HasCaught () && !try_catch.Exception ().IsEmpty ());
1050
- auto e = try_catch.Exception ()->ToObject (context).ToLocalChecked ();
1051
- auto code = e->Get (context, env->code_string ()).ToLocalChecked ();
1052
- Utf8Value code_utf8 (env->isolate (),
1053
- code->ToString (context).ToLocalChecked ());
1056
+ CHECK (try_catch.HasCaught ());
1057
+ if (try_catch.Exception ().IsEmpty ()) return Nothing<URL>();
1058
+ Local<Object> e;
1059
+ if (!try_catch.Exception ()->ToObject (context).ToLocal (&e))
1060
+ return Nothing<URL>();
1061
+ Local<Value> code;
1062
+ if (!e->Get (context, env->code_string ()).ToLocal (&code))
1063
+ return Nothing<URL>();
1064
+ Local<String> code_string;
1065
+ if (!code->ToString (context).ToLocal (&code_string))
1066
+ return Nothing<URL>();
1067
+ Utf8Value code_utf8 (env->isolate (), code_string);
1054
1068
if (strcmp (*code_utf8, " ERR_PACKAGE_PATH_NOT_EXPORTED" ) == 0 )
1055
1069
continue ;
1056
1070
try_catch.ReThrow ();
0 commit comments