From 2b8c53f9d7ad585fef8d2ab8095ca75c1c6679e9 Mon Sep 17 00:00:00 2001 From: Barrett Ruth Date: Sat, 7 Mar 2026 16:28:33 -0500 Subject: [PATCH] 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`. --- lua/cp/submit.lua | 11 ++++++++++- 1 file changed, 10 insertions(+), 1 deletion(-) diff --git a/lua/cp/submit.lua b/lua/cp/submit.lua index 6418488..e2291d6 100644 --- a/lua/cp/submit.lua +++ b/lua/cp/submit.lua @@ -53,11 +53,20 @@ function M.submit(opts) end 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 }) return end 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 cfg = config.get_config()