logger.Error("Could not update storage, rollback error",zap.Error(e))
}
returnnil,STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i))
returnStatusError(STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i)),ErrRejected)
}
// Check write permission if caller is not script runtime.
ifcaller!=""&&write.Valid&&write.Int64!=1{
returnnil,STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i))
returnStatusError(STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i)),ErrRejected)
}
// Allow updates to create new records.
@@ -535,10 +570,7 @@ WHERE bucket = $1 AND collection = $2 AND user_id = $3 AND record = $4 AND delet
// Apply the patch operations.
newValue,err:=update.Patch.Apply(value)
iferr!=nil{
ife:=tx.Rollback();e!=nil{
logger.Error("Could not update storage, rollback error",zap.Error(e))
}
returnnil,STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: %v",i,err.Error()))
returnStatusError(STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: %v",i,err.Error())),ErrRejected)
logger.Error("Could not update storage, rollback error",zap.Error(err))
}
returnnil,STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i))
returnStatusError(STORAGE_REJECTED,errors.New(fmt.Sprintf("Storage update index %v rejected: not found, version check failed, or permission denied",i)),ErrRowsAffectedCount)
}
keys[i]=&StorageKey{
@@ -590,10 +615,14 @@ DO UPDATE SET value = $6::BYTEA, version = $7, read = $8, write = $9, updated_at
}
}
// Commit the transaction.
err=tx.Commit()
returnnil
})
iferr!=nil{
logger.Error("Could not update storage, commit error",zap.Error(err))
ife,ok:=err.(*statusError);ok{
returnnil,e.Code(),e.Status()
}
logger.Error("Could not write storage, transaction error",zap.Error(err))
returnnil,RUNTIME_EXCEPTION,errors.New("Could not update storage")