Skip to content

Commit 6c4f1e2

Browse files
committed
fix: check existance of profile before modifications
1 parent a036132 commit 6c4f1e2

1 file changed

Lines changed: 21 additions & 1 deletion

File tree

lua/java/api/profile_config.lua

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -149,20 +149,25 @@ function M.get_profile(profile_name, dap_config_name)
149149
return M.project_profiles[dap_config_name][profile_name]
150150
end
151151

152-
--- @param dap_config_name_key string
152+
--- @param dap_config_name string
153153
--- @return table<string, Profile>
154154
function M.get_all_profiles(dap_config_name)
155155
return M.project_profiles[dap_config_name] or {}
156156
end
157157
--- @param dap_config_name string
158158
--- @param profile_name string
159159
function M.set_active_profile(profile_name, dap_config_name)
160+
if not M.__has_profile(profile_name, dap_config_name) then
161+
return
162+
end
163+
160164
for _, profile in pairs(M.project_profiles[dap_config_name]) do
161165
if profile.is_active then
162166
profile.is_active = false
163167
break
164168
end
165169
end
170+
166171
M.project_profiles[dap_config_name][profile_name].is_active = true
167172
M.save()
168173
end
@@ -200,10 +205,25 @@ end
200205
--- @param dap_config_name string
201206
--- @param profile_name string
202207
function M.delete_profile(profile_name, dap_config_name)
208+
if not M.__has_profile(profile_name, dap_config_name) then
209+
return
210+
end
211+
203212
M.project_profiles[dap_config_name][profile_name] = nil
204213
M.save()
205214
end
206215

216+
---Returns true if a profile exists by given name
217+
---@param profile_name string
218+
---@param dap_config_name string
219+
function M.__has_profile(profile_name, dap_config_name)
220+
if M.project_profiles[dap_config_name][profile_name] then
221+
return true
222+
end
223+
224+
return false
225+
end
226+
207227
--- @type Profile
208228
M.Profile = Profile
209229

0 commit comments

Comments
 (0)