fix: improve error handling
This commit is contained in:
parent
9134a0742b
commit
a0b5264761
6 changed files with 33 additions and 26 deletions
|
|
@ -43,18 +43,12 @@ function M.handle_cache_command(cmd)
|
||||||
if vim.tbl_contains(platforms, cmd.platform) then
|
if vim.tbl_contains(platforms, cmd.platform) then
|
||||||
cache.clear_platform(cmd.platform)
|
cache.clear_platform(cmd.platform)
|
||||||
logger.log(
|
logger.log(
|
||||||
('Cache cleared for platform %s'):format(cmd.platform),
|
("Cache cleared for platform '%s'"):format(constants.PLATFORM_DISPLAY_NAMES[cmd.platform]),
|
||||||
vim.log.levels.INFO,
|
vim.log.levels.INFO,
|
||||||
true
|
true
|
||||||
)
|
)
|
||||||
else
|
else
|
||||||
logger.log(
|
logger.log(("Unknown platform '%s'."):format(cmd.platform), vim.log.levels.ERROR)
|
||||||
("Unknown platform: '%s'. Available: %s"):format(
|
|
||||||
cmd.platform,
|
|
||||||
table.concat(platforms, ', ')
|
|
||||||
),
|
|
||||||
vim.log.levels.ERROR
|
|
||||||
)
|
|
||||||
end
|
end
|
||||||
else
|
else
|
||||||
cache.clear_all()
|
cache.clear_all()
|
||||||
|
|
|
||||||
|
|
@ -136,7 +136,11 @@ function M.handle_command(opts)
|
||||||
|
|
||||||
if not (contest_data and contest_data.index_map and contest_data.index_map[problem_id]) then
|
if not (contest_data and contest_data.index_map and contest_data.index_map[problem_id]) then
|
||||||
logger.log(
|
logger.log(
|
||||||
("%s contest '%s' has no problem '%s'."):format(platform, contest_id, problem_id),
|
("%s contest '%s' has no problem '%s'."):format(
|
||||||
|
constants.PLATFORM_DISPLAY_NAMES[platform],
|
||||||
|
contest_id,
|
||||||
|
problem_id
|
||||||
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -4,13 +4,13 @@ local M = {}
|
||||||
|
|
||||||
local function contest_picker(platform, refresh)
|
local function contest_picker(platform, refresh)
|
||||||
local constants = require('cp.constants')
|
local constants = require('cp.constants')
|
||||||
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform] or platform
|
local platform_display_name = constants.PLATFORM_DISPLAY_NAMES[platform]
|
||||||
local fzf = require('fzf-lua')
|
local fzf = require('fzf-lua')
|
||||||
local contests = picker_utils.get_platform_contests(platform, refresh)
|
local contests = picker_utils.get_platform_contests(platform, refresh)
|
||||||
|
|
||||||
if vim.tbl_isempty(contests) then
|
if vim.tbl_isempty(contests) then
|
||||||
vim.notify(
|
vim.notify(
|
||||||
('No contests found for platform: %s'):format(platform_display_name),
|
("No contests found for platform '%s'"):format(platform_display_name),
|
||||||
vim.log.levels.WARN
|
vim.log.levels.WARN
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -1,4 +1,6 @@
|
||||||
local M = {}
|
local M = {}
|
||||||
|
|
||||||
|
local constants = require('cp.log')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local utils = require('cp.utils')
|
local utils = require('cp.utils')
|
||||||
|
|
||||||
|
|
@ -113,7 +115,10 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
||||||
on_exit = function(result)
|
on_exit = function(result)
|
||||||
if not result or not result.success then
|
if not result or not result.success then
|
||||||
logger.log(
|
logger.log(
|
||||||
("Failed to scrape metadata for %s contest '%s'."):format(platform, contest_id),
|
("Failed to scrape metadata for %s contest '%s'."):format(
|
||||||
|
constants.PLATFORM_DISPLAY_NAMES[platform],
|
||||||
|
contest_id
|
||||||
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
@ -121,7 +126,10 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
||||||
local data = result.data or {}
|
local data = result.data or {}
|
||||||
if not data.problems or #data.problems == 0 then
|
if not data.problems or #data.problems == 0 then
|
||||||
logger.log(
|
logger.log(
|
||||||
("No problems returned for %s contest '%s'."):format(platform, contest_id),
|
("No problems returned for %s contest '%s'."):format(
|
||||||
|
constants.PLATFORM_DISPLAY_NAMES[platform],
|
||||||
|
contest_id
|
||||||
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
|
||||||
|
|
@ -11,10 +11,7 @@ local platforms = constants.PLATFORMS
|
||||||
|
|
||||||
function M.set_platform(platform)
|
function M.set_platform(platform)
|
||||||
if not vim.tbl_contains(platforms, platform) then
|
if not vim.tbl_contains(platforms, platform) then
|
||||||
logger.log(
|
logger.log(("Unknown platform '%s'"):format(platform), vim.log.levels.ERROR)
|
||||||
('unknown platform: %s. supported: %s'):format(platform, table.concat(platforms, ', ')),
|
|
||||||
vim.log.levels.ERROR
|
|
||||||
)
|
|
||||||
return false
|
return false
|
||||||
end
|
end
|
||||||
state.set_platform(platform)
|
state.set_platform(platform)
|
||||||
|
|
|
||||||
|
|
@ -4,6 +4,7 @@ local M = {}
|
||||||
---@field debug? boolean
|
---@field debug? boolean
|
||||||
|
|
||||||
local config_module = require('cp.config')
|
local config_module = require('cp.config')
|
||||||
|
local constants = require('cp.constants')
|
||||||
local layouts = require('cp.ui.layouts')
|
local layouts = require('cp.ui.layouts')
|
||||||
local logger = require('cp.log')
|
local logger = require('cp.log')
|
||||||
local state = require('cp.state')
|
local state = require('cp.state')
|
||||||
|
|
@ -58,7 +59,10 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
end
|
end
|
||||||
if not contest_id then
|
if not contest_id then
|
||||||
logger.log(
|
logger.log(
|
||||||
('No contest %s configured for platform %s.'):format(contest_id, platform),
|
("No contest %s configured for platform '%s'."):format(
|
||||||
|
contest_id,
|
||||||
|
constants.PLATFORM_DISPLAY_NAMES[platform]
|
||||||
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
|
|
@ -107,7 +111,10 @@ function M.toggle_interactive(interactor_cmd)
|
||||||
interactor = './' .. interactor
|
interactor = './' .. interactor
|
||||||
end
|
end
|
||||||
if vim.fn.executable(interactor) ~= 1 then
|
if vim.fn.executable(interactor) ~= 1 then
|
||||||
logger.log(('Interactor not executable: %s'):format(interactor_cmd), vim.log.levels.ERROR)
|
logger.log(
|
||||||
|
("Interactor '%s' is not executable."):format(interactor_cmd),
|
||||||
|
vim.log.levels.ERROR
|
||||||
|
)
|
||||||
if state.saved_interactive_session then
|
if state.saved_interactive_session then
|
||||||
vim.cmd(('source %s'):format(state.saved_interactive_session))
|
vim.cmd(('source %s'):format(state.saved_interactive_session))
|
||||||
vim.fn.delete(state.saved_interactive_session)
|
vim.fn.delete(state.saved_interactive_session)
|
||||||
|
|
@ -231,18 +238,15 @@ function M.toggle_run_panel(run_opts)
|
||||||
|
|
||||||
if not contest_id then
|
if not contest_id then
|
||||||
logger.log(
|
logger.log(
|
||||||
('No contest %s configured for platform %s.'):format(contest_id, platform),
|
("No contest '%s' configured for platform '%s'."):format(
|
||||||
|
contest_id,
|
||||||
|
constants.PLATFORM_DISPLAY_NAMES[platform]
|
||||||
|
),
|
||||||
vim.log.levels.ERROR
|
vim.log.levels.ERROR
|
||||||
)
|
)
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
|
|
||||||
local problem_id = state.get_problem_id()
|
|
||||||
if not problem_id then
|
|
||||||
logger.log(('No problem found for the current problem id %s'):format(problem_id))
|
|
||||||
return
|
|
||||||
end
|
|
||||||
|
|
||||||
local cache = require('cp.cache')
|
local cache = require('cp.cache')
|
||||||
cache.load()
|
cache.load()
|
||||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue