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
|
||||
cache.clear_platform(cmd.platform)
|
||||
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,
|
||||
true
|
||||
)
|
||||
else
|
||||
logger.log(
|
||||
("Unknown platform: '%s'. Available: %s"):format(
|
||||
cmd.platform,
|
||||
table.concat(platforms, ', ')
|
||||
),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
logger.log(("Unknown platform '%s'."):format(cmd.platform), vim.log.levels.ERROR)
|
||||
end
|
||||
else
|
||||
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
|
||||
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
|
||||
)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -4,13 +4,13 @@ local M = {}
|
|||
|
||||
local function contest_picker(platform, refresh)
|
||||
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 contests = picker_utils.get_platform_contests(platform, refresh)
|
||||
|
||||
if vim.tbl_isempty(contests) then
|
||||
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
|
||||
)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -1,4 +1,6 @@
|
|||
local M = {}
|
||||
|
||||
local constants = require('cp.log')
|
||||
local logger = require('cp.log')
|
||||
local utils = require('cp.utils')
|
||||
|
||||
|
|
@ -113,7 +115,10 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
|||
on_exit = function(result)
|
||||
if not result or not result.success then
|
||||
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
|
||||
)
|
||||
return
|
||||
|
|
@ -121,7 +126,10 @@ function M.scrape_contest_metadata(platform, contest_id, callback)
|
|||
local data = result.data or {}
|
||||
if not data.problems or #data.problems == 0 then
|
||||
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
|
||||
)
|
||||
return
|
||||
|
|
|
|||
|
|
@ -11,10 +11,7 @@ local platforms = constants.PLATFORMS
|
|||
|
||||
function M.set_platform(platform)
|
||||
if not vim.tbl_contains(platforms, platform) then
|
||||
logger.log(
|
||||
('unknown platform: %s. supported: %s'):format(platform, table.concat(platforms, ', ')),
|
||||
vim.log.levels.ERROR
|
||||
)
|
||||
logger.log(("Unknown platform '%s'"):format(platform), vim.log.levels.ERROR)
|
||||
return false
|
||||
end
|
||||
state.set_platform(platform)
|
||||
|
|
|
|||
|
|
@ -4,6 +4,7 @@ local M = {}
|
|||
---@field debug? boolean
|
||||
|
||||
local config_module = require('cp.config')
|
||||
local constants = require('cp.constants')
|
||||
local layouts = require('cp.ui.layouts')
|
||||
local logger = require('cp.log')
|
||||
local state = require('cp.state')
|
||||
|
|
@ -58,7 +59,10 @@ function M.toggle_interactive(interactor_cmd)
|
|||
end
|
||||
if not contest_id then
|
||||
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
|
||||
)
|
||||
return
|
||||
|
|
@ -107,7 +111,10 @@ function M.toggle_interactive(interactor_cmd)
|
|||
interactor = './' .. interactor
|
||||
end
|
||||
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
|
||||
vim.cmd(('source %s'):format(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
|
||||
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
|
||||
)
|
||||
return
|
||||
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')
|
||||
cache.load()
|
||||
local contest_data = cache.get_contest_data(platform, contest_id)
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue