feat(submit): guard against submitting an empty source file
Problem: if the source file exists but is empty, the scraper would send a blank submission to the platform. Solution: resolve the path to absolute before checking, use `vim.uv.fs_stat` to verify existence, and abort with a WARN if `stat.size == 0`.
This commit is contained in:
parent
835119ccd6
commit
2b8c53f9d7
1 changed files with 10 additions and 1 deletions
|
|
@ -53,11 +53,20 @@ function M.submit(opts)
|
||||||
end
|
end
|
||||||
|
|
||||||
local source_file = state.get_source_file()
|
local source_file = state.get_source_file()
|
||||||
if not source_file or vim.fn.filereadable(source_file) ~= 1 then
|
if not source_file then
|
||||||
logger.log('Source file not found', { level = vim.log.levels.ERROR })
|
logger.log('Source file not found', { level = vim.log.levels.ERROR })
|
||||||
return
|
return
|
||||||
end
|
end
|
||||||
source_file = vim.fn.fnamemodify(source_file, ':p')
|
source_file = vim.fn.fnamemodify(source_file, ':p')
|
||||||
|
local _stat = vim.uv.fs_stat(source_file)
|
||||||
|
if not _stat then
|
||||||
|
logger.log('Source file not found', { level = vim.log.levels.ERROR })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
if _stat.size == 0 then
|
||||||
|
logger.log('Submit aborted: source file has no content', { level = vim.log.levels.WARN })
|
||||||
|
return
|
||||||
|
end
|
||||||
|
|
||||||
local submit_language = language
|
local submit_language = language
|
||||||
local cfg = config.get_config()
|
local cfg = config.get_config()
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue