From 48957dd2b76606f69549ddc3bd9f79d2e02d141e Mon Sep 17 00:00:00 2001 From: mbdavid Date: Fri, 21 Feb 2020 16:10:27 -0300 Subject: [PATCH] New 5.0.3 with more debug info --- LiteDB/Engine/Pages/CollectionPage.cs | 2 +- LiteDB/Engine/Pages/DataPage.cs | 2 +- LiteDB/Engine/Pages/IndexPage.cs | 2 +- LiteDB/LiteDB.csproj | 8 ++++---- LiteDB/Utils/LiteException.cs | 14 ++++++++++++++ 5 files changed, 21 insertions(+), 7 deletions(-) diff --git a/LiteDB/Engine/Pages/CollectionPage.cs b/LiteDB/Engine/Pages/CollectionPage.cs index 5a7aa76c4..98b746492 100644 --- a/LiteDB/Engine/Pages/CollectionPage.cs +++ b/LiteDB/Engine/Pages/CollectionPage.cs @@ -41,7 +41,7 @@ public CollectionPage(PageBuffer buffer) { ENSURE(this.PageType == PageType.Collection, "page type must be collection page"); - if (this.PageType != PageType.Collection) throw new LiteException(0, $"Invalid CollectionPage buffer on {PageID}"); + if (this.PageType != PageType.Collection) LiteException.InvalidPageType(PageType.Collection, this); // create new buffer area to store BsonDocument indexes var area = _buffer.Slice(PAGE_HEADER_SIZE, PAGE_SIZE - PAGE_HEADER_SIZE); diff --git a/LiteDB/Engine/Pages/DataPage.cs b/LiteDB/Engine/Pages/DataPage.cs index fe7dba48f..491f3bf67 100644 --- a/LiteDB/Engine/Pages/DataPage.cs +++ b/LiteDB/Engine/Pages/DataPage.cs @@ -18,7 +18,7 @@ public DataPage(PageBuffer buffer) { ENSURE(this.PageType == PageType.Data, "page type must be data page"); - if (this.PageType != PageType.Data) throw new LiteException(0, $"Invalid DataPage buffer on {PageID}"); + if (this.PageType != PageType.Data) LiteException.InvalidPageType(PageType.Data, this); } /// diff --git a/LiteDB/Engine/Pages/IndexPage.cs b/LiteDB/Engine/Pages/IndexPage.cs index 92f1ebef2..2961377e3 100644 --- a/LiteDB/Engine/Pages/IndexPage.cs +++ b/LiteDB/Engine/Pages/IndexPage.cs @@ -18,7 +18,7 @@ public IndexPage(PageBuffer buffer) { ENSURE(this.PageType == PageType.Index, "page type must be index page"); - if (this.PageType != PageType.Index) throw new LiteException(0, $"Invalid IndexPage buffer on {PageID}"); + if (this.PageType != PageType.Index) LiteException.InvalidPageType(PageType.Index, this); } /// diff --git a/LiteDB/LiteDB.csproj b/LiteDB/LiteDB.csproj index 7867ab4f2..f2a4835eb 100644 --- a/LiteDB/LiteDB.csproj +++ b/LiteDB/LiteDB.csproj @@ -2,9 +2,9 @@ net45;netstandard1.3;netstandard2.0 - 5.0.2 - 5.0.2 - 5.0.2 + 5.0.3 + 5.0.3 + 5.0.3 Maurício David LiteDB LiteDB - A lightweight embedded .NET NoSQL document store in a single datafile @@ -12,7 +12,7 @@ en-US LiteDB LiteDB - 5.0.2 + 5.0.3 database nosql embedded icon_64x64.png LICENSE diff --git a/LiteDB/Utils/LiteException.cs b/LiteDB/Utils/LiteException.cs index 3817af446..1c36c5ada 100644 --- a/LiteDB/Utils/LiteException.cs +++ b/LiteDB/Utils/LiteException.cs @@ -1,6 +1,7 @@ using LiteDB.Engine; using System; using System.Reflection; +using System.Text; using System.Threading.Tasks; using static LiteDB.Constants; @@ -268,6 +269,19 @@ internal static LiteException InvalidTypedName(string type) return new LiteException(INVALID_TYPED_NAME, "Type '{0}' not found in current domain (_type format is 'Type.FullName, AssemblyName').", type); } + internal static LiteException InvalidPageType(PageType pageType, BasePage page) + { + var sb = new StringBuilder($"Invalid {pageType} on {page.PageID}. "); + + sb.Append($"Full zero: {page.Buffer.All(0)}. "); + sb.Append($"Page Type: {page.PageType}. "); + sb.Append($"Prev/Next: {page.PrevPageID}/{page.NextPageID}. "); + sb.Append($"UniqueID: {page.Buffer.UniqueID}. "); + sb.Append($"ShareCounter: {page.Buffer.ShareCounter}. "); + + return new LiteException(0, sb.ToString()); + } + #endregion } } \ No newline at end of file