@@ -364,7 +364,18 @@ fn update_local_items_in_places(
364364
365365 log:: debug!( "Changing GUIDs" ) ;
366366 scope. err_if_interrupted ( ) ?;
367- db. execute_batch ( "DELETE FROM changeGuidOps" ) ?;
367+ let result = db. execute_batch ( "DELETE FROM changeGuidOps" ) ;
368+ // Due to bug 1935797, guid collisions are happening in some step of bookmarks
369+ // but not clear if it's the "fixup" step, so we catch and log to sentry
370+ if let Err ( rusqlite:: Error :: SqliteFailure ( e, _) ) = & result {
371+ if e. code == ErrorCode :: ConstraintViolation {
372+ error_support:: report_error!(
373+ "places-sync-bookmarks-guid-collision" ,
374+ "changeGuidOps ran into guid collision violation"
375+ ) ;
376+ }
377+ }
378+ result?;
368379
369380 log:: debug!( "Applying remote items" ) ;
370381 apply_remote_items ( db, scope, now) ?;
@@ -374,6 +385,35 @@ fn update_local_items_in_places(
374385 scope. err_if_interrupted ( ) ?;
375386 db. execute_batch ( "DELETE FROM applyNewLocalStructureOps" ) ?;
376387
388+ // Similar to the check in apply_remote_items, however we do a post check
389+ // to see if dogear was unable to fix up the issue
390+ let orphaned_count: i64 = db. query_row (
391+ "WITH RECURSIVE orphans(id) AS (
392+ SELECT b.id
393+ FROM moz_bookmarks b
394+ WHERE b.parent IS NOT NULL
395+ AND NOT EXISTS (
396+ SELECT 1 FROM moz_bookmarks p WHERE p.id = b.parent
397+ )
398+ UNION
399+ SELECT c.id
400+ FROM moz_bookmarks c
401+ JOIN orphans o ON c.parent = o.id
402+ )
403+ SELECT COUNT(*) FROM orphans;" ,
404+ [ ] ,
405+ |row| row. get ( 0 ) ,
406+ ) ?;
407+
408+ if orphaned_count > 0 {
409+ log:: warn!( "Found {} orphaned bookmarks after sync" , orphaned_count) ;
410+ error_support:: report_error!(
411+ "places-sync-bookmarks-orphaned" ,
412+ "found local orphaned bookmarks after we applied new local structure ops: {}" ,
413+ orphaned_count,
414+ ) ;
415+ }
416+
377417 log:: debug!( "Resetting change counters for items that shouldn't be uploaded" ) ;
378418 sql_support:: each_chunk_mapped (
379419 & ops. set_local_merged ,
@@ -491,8 +531,8 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
491531 }
492532 ) . ok ( ) ; // We ignore the error because it's expected, users should not have entries with the same id that have different types
493533
494- // Same as above but we check if any users have any undetected orphaned bookmarks and
495- // report them appropiately
534+ // Due to bug 1935797, we need to check if any users have any
535+ // undetected orphaned bookmarks and report them
496536 let orphaned_count: i64 = db. query_row (
497537 "WITH RECURSIVE orphans(id) AS (
498538 SELECT b.id
@@ -513,9 +553,8 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
513553
514554 if orphaned_count > 0 {
515555 log:: warn!( "Found {} orphaned bookmarks during sync" , orphaned_count) ;
516- error_support:: report_error!(
517- "places-sync-bookmarks-orphaned" ,
518- "found local orphaned bookmarks {}" ,
556+ error_support:: breadcrumb!(
557+ "places-sync-bookmarks-orphaned: found local orphans before upsert {}" ,
519558 orphaned_count
520559 ) ;
521560 }
@@ -559,7 +598,7 @@ fn apply_remote_items(db: &PlacesDb, scope: &SqlInterruptScope, now: Timestamp)
559598 let result = db. execute_batch ( & upsert_sql) ;
560599
561600 // In trying to debug bug 1935797 - relaxing the trigger caused a spike on
562- // guid collisions, we want to report on this error before the actual upsert to see
601+ // guid collisions, we want to report on this during the upsert to see
563602 // if we can discern any obvious signs
564603 if let Err ( rusqlite:: Error :: SqliteFailure ( e, _) ) = & result {
565604 if e. code == ErrorCode :: ConstraintViolation {
0 commit comments