@@ -59,15 +59,15 @@ static void Has(const FunctionCallbackInfo<Value>& args) {
59
59
60
60
} // namespace
61
61
62
- #define V (Name, label, _ ) \
62
+ #define V (Name, label, _, __ ) \
63
63
if (perm == PermissionScope::k##Name) return #Name;
64
64
const char * Permission::PermissionToString (const PermissionScope perm) {
65
65
PERMISSIONS (V)
66
66
return nullptr ;
67
67
}
68
68
#undef V
69
69
70
- #define V (Name, label, _ ) \
70
+ #define V (Name, label, _, __ ) \
71
71
if (perm == label) return PermissionScope::k##Name;
72
72
PermissionScope Permission::StringToPermission (const std::string& perm) {
73
73
PERMISSIONS (V)
@@ -84,32 +84,47 @@ Permission::Permission() : enabled_(false) {
84
84
std::shared_ptr<PermissionBase> inspector =
85
85
std::make_shared<InspectorPermission>();
86
86
std::shared_ptr<PermissionBase> wasi = std::make_shared<WASIPermission>();
87
- #define V (Name, _, __ ) \
87
+ #define V (Name, _, __, ___ ) \
88
88
nodes_.insert (std::make_pair (PermissionScope::k##Name, fs));
89
89
FILESYSTEM_PERMISSIONS (V)
90
90
#undef V
91
- #define V (Name, _, __ ) \
91
+ #define V (Name, _, __, ___ ) \
92
92
nodes_.insert (std::make_pair (PermissionScope::k##Name, child_p));
93
93
CHILD_PROCESS_PERMISSIONS (V)
94
94
#undef V
95
- #define V (Name, _, __ ) \
95
+ #define V (Name, _, __, ___ ) \
96
96
nodes_.insert (std::make_pair (PermissionScope::k##Name, worker_t ));
97
97
WORKER_THREADS_PERMISSIONS (V)
98
98
#undef V
99
- #define V (Name, _, __ ) \
99
+ #define V (Name, _, __, ___ ) \
100
100
nodes_.insert (std::make_pair (PermissionScope::k##Name, inspector));
101
101
INSPECTOR_PERMISSIONS (V)
102
102
#undef V
103
- #define V (Name, _, __ ) \
103
+ #define V (Name, _, __, ___ ) \
104
104
nodes_.insert (std::make_pair (PermissionScope::k##Name, wasi));
105
105
WASI_PERMISSIONS (V)
106
106
#undef V
107
107
}
108
108
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
+
109
121
MaybeLocal<Value> CreateAccessDeniedError (Environment* env,
110
122
PermissionScope perm,
111
123
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
+
113
128
Local<Value> perm_string;
114
129
Local<Value> resource_string;
115
130
std::string_view perm_str = Permission::PermissionToString (perm);
0 commit comments