@@ -1697,36 +1697,15 @@ func (db *DatabaseCollectionWithUser) PutExistingRevWithBody(ctx context.Context
16971697// SyncFnDryrun Runs a document through the sync function and returns expiry, channels doc was placed in, access map for users, roles, handler errors and sync fn exceptions.
16981698// If a docID is a non empty string, the document will be fetched from the bucket, otherwise the body will be used. If both are specified, this function returns an error.
16991699// The first error return value represents an error that occurs before the sync function is run. The second error return value represents an exception from the sync function.
1700- func (db * DatabaseCollectionWithUser ) SyncFnDryrun (ctx context.Context , body Body , docID , syncFn string ) (* channels.ChannelMapperOutput , error , error ) {
1701- doc := & Document {
1702- ID : docID ,
1703- _body : body ,
1704- }
1705- oldDoc := doc
1706- if docID != "" {
1707- if docInBucket , err := db .GetDocument (ctx , docID , DocUnmarshalAll ); err == nil {
1708- oldDoc = docInBucket
1709- if len (doc ._body ) == 0 {
1710- body = oldDoc .Body (ctx )
1711- doc ._body = body
1712- // If no body is given, use doc in bucket as doc with no old doc
1713- oldDoc ._body = nil
1714- }
1715- doc ._body [BodyRev ] = oldDoc .SyncData .GetRevTreeID ()
1716- } else {
1717- return nil , err , nil
1718- }
1719- } else {
1720- oldDoc ._body = nil
1721- }
1700+ func (db * DatabaseCollectionWithUser ) SyncFnDryrun (ctx context.Context , oldDoc * Document , body Body , docID , syncFn string ) (* channels.ChannelMapperOutput , error ) {
17221701
17231702 delete (body , BodyId )
17241703
17251704 // Get the revision ID to match, and the new generation number:
17261705 matchRev , _ := body [BodyRev ].(string )
17271706 generation , _ := ParseRevID (ctx , matchRev )
17281707 if generation < 0 {
1729- return nil , base .HTTPErrorf (http .StatusBadRequest , "Invalid revision ID" ), nil
1708+ return nil , base .HTTPErrorf (http .StatusBadRequest , "Invalid revision ID" )
17301709 }
17311710 generation ++
17321711
@@ -1742,12 +1721,12 @@ func (db *DatabaseCollectionWithUser) SyncFnDryrun(ctx context.Context, body Bod
17421721
17431722 err := validateAPIDocUpdate (body )
17441723 if err != nil {
1745- return nil , err , nil
1724+ return nil , err
17461725 }
17471726 bodyWithoutInternalProps , wasStripped := StripInternalProperties (body )
17481727 canonicalBytesForRevID , err := base .JSONMarshalCanonical (bodyWithoutInternalProps )
17491728 if err != nil {
1750- return nil , err , nil
1729+ return nil , err
17511730 }
17521731
17531732 // We needed to keep _deleted around in the body until we generated a rev ID, but now we can ditch it.
@@ -1770,30 +1749,33 @@ func (db *DatabaseCollectionWithUser) SyncFnDryrun(ctx context.Context, body Bod
17701749 mutableBody , metaMap , _ , err := db .prepareSyncFn (oldDoc , newDoc )
17711750 if err != nil {
17721751 base .InfofCtx (ctx , base .KeyDiagnostic , "Failed to prepare to run sync function: %v" , err )
1773- return nil , err , nil
1752+ return nil , err
17741753 }
17751754
17761755 syncOptions , err := MakeUserCtx (db .user , db .ScopeName , db .Name )
17771756 if err != nil {
1778- return nil , err , nil
1757+ return nil , err
17791758 }
17801759 var output * channels.ChannelMapperOutput
17811760 if syncFn == "" {
17821761 output , err = db .ChannelMapper .MapToChannelsAndAccess (ctx , mutableBody , string (oldDoc ._rawBody ), metaMap , syncOptions )
1762+ if err != nil {
1763+ err = fmt .Errorf ("%s%s" , base .ErrSyncFnDryRun , err )
1764+ }
17831765 } else {
17841766 jsTimeout := time .Duration (base .DefaultJavascriptTimeoutSecs ) * time .Second
17851767 syncRunner , err := channels .NewSyncRunner (ctx , syncFn , jsTimeout )
17861768 if err != nil {
1787- return nil , fmt .Errorf ("failed to create sync runner: %v" , err ), nil
1769+ return nil , fmt .Errorf ("failed to create sync runner: %v" , err )
17881770 }
17891771 jsOutput , err := syncRunner .Call (ctx , mutableBody , string (oldDoc ._rawBody ), metaMap , syncOptions )
17901772 if err != nil {
1791- return nil , err , nil
1773+ err = fmt . Errorf ( "%s%s" , base . ErrSyncFnDryRun , err )
17921774 }
17931775 output = jsOutput .(* channels.ChannelMapperOutput )
17941776 }
17951777
1796- return output , nil , err
1778+ return output , err
17971779}
17981780
17991781// revTreeConflictCheck checks for conflicts in the rev tree history and returns the parent revid, currentRevIndex
0 commit comments