@@ -52,6 +52,7 @@ import Share.Web.Errors
5252import Share.Web.UCM.Sync.HashJWT qualified as HashJWT
5353import Share.Web.UCM.Sync.Types (EntityBunch (.. ), RepoInfoKind (.. ), entityKind )
5454import U.Codebase.Causal qualified as Causal
55+ import U.Codebase.Sqlite.HashHandle qualified as HH
5556import U.Codebase.Sqlite.Orphans ()
5657import Unison.Codebase.Path qualified as Path
5758import Unison.Hash32 (Hash32 )
@@ -259,7 +260,11 @@ insertEntitiesToCodebase codebase entities = do
259260 mayErrs <- PG. transactionUnsafeIO $ batchValidateEntities maxParallelismPerUploadRequest isComponentHashMismatchAllowedIO isCausalHashMismatchAllowedIO unsavedEntities
260261 case mayErrs of
261262 Nothing -> pure ()
262- Just (err :| _errs) -> throwError err
263+ Just (err :| _errs) ->
264+ case err of
265+ Right e -> throwError e
266+ Left (HH. IncompleteElementOrderingError (ComponentHash hash)) ->
267+ throwError $ Sync. InvalidByteEncoding (Hash32. fromHash hash) Sync. TermComponentType " Incomplete element ordering in term components"
263268 SyncQ. saveTempEntities codebase unsavedEntities
264269 let hashesNowInTemp = Set. fromList (fst <$> Foldable. toList unsavedEntities) <> (Set. fromList . Foldable. toList $ hashesAlreadyInTemp)
265270 pure hashesNowInTemp
@@ -393,7 +398,7 @@ batchValidateEntities ::
393398 (ComponentHash -> ComponentHash -> IO Bool ) ->
394399 (CausalHash -> CausalHash -> IO Bool ) ->
395400 f (Hash32 , Sync. Entity Text Hash32 Hash32 ) ->
396- IO (Maybe (NonEmpty (Sync. EntityValidationError )))
401+ IO (Maybe (NonEmpty (Either HH. IncompleteElementOrderingError Sync. EntityValidationError )))
397402batchValidateEntities maxParallelism checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed entities = do
398403 errs <- UnliftIO. pooledForConcurrentlyN maxParallelism entities \ (hash, entity) ->
399404 validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity
@@ -405,16 +410,16 @@ validateEntity ::
405410 (CausalHash -> CausalHash -> m Bool ) ->
406411 Hash32 ->
407412 Share. Entity Text Hash32 Hash32 ->
408- m (Maybe Sync. EntityValidationError )
413+ m (Maybe ( Either HH. IncompleteElementOrderingError Sync. EntityValidationError) )
409414validateEntity checkIfComponentHashMismatchIsAllowed checkIfCausalHashMismatchIsAllowed hash entity = do
410415 case (Sync. validateEntity hash entity) of
411- Just err@ (Sync. EntityHashMismatch Sync. TermComponentType (Sync. HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) ->
416+ Just ( Right ( err@ (Sync. EntityHashMismatch Sync. TermComponentType (Sync. HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) )) ->
412417 checkIfComponentHashMismatchIsAllowed (ComponentHash . Hash32. toHash $ expectedHash) (ComponentHash . Hash32. toHash $ actualHash) >>= \ case
413- False -> pure (Just err)
418+ False -> pure (Just $ Right err)
414419 True -> pure Nothing
415- Just err@ (Sync. EntityHashMismatch Sync. CausalType (Sync. HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) ->
420+ Just ( Right ( err@ (Sync. EntityHashMismatch Sync. CausalType (Sync. HashMismatchForEntity {supplied = expectedHash, computed = actualHash})) )) ->
416421 checkIfCausalHashMismatchIsAllowed (CausalHash . Hash32. toHash $ expectedHash) (CausalHash . Hash32. toHash $ actualHash) >>= \ case
417- False -> pure (Just err)
422+ False -> pure (Just $ Right err)
418423 True -> pure Nothing
419424 Just err ->
420425 -- This shouldn't happen unless the ucm client is buggy or malicious
0 commit comments