@@ -59,15 +59,15 @@ static void Has(const FunctionCallbackInfo<Value>& args) {
5959
6060} // namespace
6161
62- #define V (Name, label, _ ) \
62+ #define V (Name, label, _, __ ) \
6363 if (perm == PermissionScope::k##Name) return #Name;
6464const char * Permission::PermissionToString (const PermissionScope perm) {
6565 PERMISSIONS (V)
6666 return nullptr ;
6767}
6868#undef V
6969
70- #define V (Name, label, _ ) \
70+ #define V (Name, label, _, __ ) \
7171 if (perm == label) return PermissionScope::k##Name;
7272PermissionScope Permission::StringToPermission (const std::string& perm) {
7373 PERMISSIONS (V)
@@ -84,32 +84,47 @@ Permission::Permission() : enabled_(false) {
8484 std::shared_ptr<PermissionBase> inspector =
8585 std::make_shared<InspectorPermission>();
8686 std::shared_ptr<PermissionBase> wasi = std::make_shared<WASIPermission>();
87- #define V (Name, _, __ ) \
87+ #define V (Name, _, __, ___ ) \
8888 nodes_.insert (std::make_pair (PermissionScope::k##Name, fs));
8989 FILESYSTEM_PERMISSIONS (V)
9090#undef V
91- #define V (Name, _, __ ) \
91+ #define V (Name, _, __, ___ ) \
9292 nodes_.insert (std::make_pair (PermissionScope::k##Name, child_p));
9393 CHILD_PROCESS_PERMISSIONS (V)
9494#undef V
95- #define V (Name, _, __ ) \
95+ #define V (Name, _, __, ___ ) \
9696 nodes_.insert (std::make_pair (PermissionScope::k##Name, worker_t ));
9797 WORKER_THREADS_PERMISSIONS (V)
9898#undef V
99- #define V (Name, _, __ ) \
99+ #define V (Name, _, __, ___ ) \
100100 nodes_.insert (std::make_pair (PermissionScope::k##Name, inspector));
101101 INSPECTOR_PERMISSIONS (V)
102102#undef V
103- #define V (Name, _, __ ) \
103+ #define V (Name, _, __, ___ ) \
104104 nodes_.insert (std::make_pair (PermissionScope::k##Name, wasi));
105105 WASI_PERMISSIONS (V)
106106#undef V
107107}
108108
109+ const char * GetErrorFlagSuggestion (node::permission::PermissionScope perm) {
110+ switch (perm) {
111+ #define V (Name, _, __, Flag ) \
112+ case node::permission::PermissionScope::k##Name: \
113+ return Flag[0 ] != ' \0 ' ? " Use " Flag " to manage permissions." : " " ;
114+ PERMISSIONS (V)
115+ #undef V
116+ default :
117+ return " " ;
118+ }
119+ }
120+
109121MaybeLocal<Value> CreateAccessDeniedError (Environment* env,
110122 PermissionScope perm,
111123 const std::string_view& res) {
112- Local<Object> err = ERR_ACCESS_DENIED (env->isolate ());
124+ const char * suggestion = GetErrorFlagSuggestion (perm);
125+ Local<Object> err = ERR_ACCESS_DENIED (
126+ env->isolate (), " Access to this API has been restricted. %s" , suggestion);
127+
113128 Local<Value> perm_string;
114129 Local<Value> resource_string;
115130 std::string_view perm_str = Permission::PermissionToString (perm);
0 commit comments