From 5dbefc5dde548c528533b6dae896a589b3b677d7 Mon Sep 17 00:00:00 2001 From: Gus Date: Sun, 5 Apr 2026 12:51:44 -0600 Subject: [PATCH] Add diagnostic warning when source database is overwritten by target init MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit When initializeTargetDatabase is called on a file that was previously marked as a source, log a warning. This should never happen during normal builds — it indicates a source file is being incorrectly treated as a build target, which corrupts the database and leads to permanent "No rule to build" errors. This diagnostic will help identify the root cause of source database corruption that some users have reported after branch switches. Co-Authored-By: Claude Opus 4.6 (1M context) --- src/Database.hs | 12 +++++++++++- 1 file changed, 11 insertions(+), 1 deletion(-) diff --git a/src/Database.hs b/src/Database.hs index 5df57e9..1b6bf6d 100644 --- a/src/Database.hs +++ b/src/Database.hs @@ -8,6 +8,7 @@ module Database (clearRedoTempDirectory, initializeTargetDatabase, hasAlwaysDep, getStdoutFile, getTempFile, markBuilt, isBuilt, markErrored, isErrored) where import Control.Exception (catch, SomeException(..)) +import Control.Monad (when) import qualified Data.ByteString.Char8 as BS import Crypto.Hash (hashWith, MD5(..), Digest) import qualified Data.ByteArray @@ -377,7 +378,16 @@ createRedoTempDirectory = do -- dependencies hanging around if we are rebuilding a file. initializeTargetDatabase :: Key -> DoFile -> IO () initializeTargetDatabase key doFile = withDatabaseLock key func - where func = do refreshDatabase key + where func = do -- Diagnostic: warn if we're about to overwrite a source-marked + -- database. This should never happen during normal builds — it + -- means a file that redo knows is a source is being treated as + -- a build target. Logging this will help diagnose the root cause + -- of "No rule to build" errors for source files. + wasSource <- doesEntryExist =<< getSourceEntry key + when wasSource $ putWarningStrLn $ + "Warning: initializeTargetDatabase is overwriting a source-marked database " ++ + "(do file: " ++ unDoFile doFile ++ "). This may corrupt redo state." + refreshDatabase key -- Write out .do script as dependency: storeIfChangeDep' key (Target $ unDoFile doFile) -- Cache the do file: