Skip to content

Commit

Permalink
New 5.0.3 with more debug info
Browse files Browse the repository at this point in the history
  • Loading branch information
mbdavid committed Feb 21, 2020
1 parent 17e8031 commit 48957dd
Show file tree
Hide file tree
Showing 5 changed files with 21 additions and 7 deletions.
2 changes: 1 addition & 1 deletion LiteDB/Engine/Pages/CollectionPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Pages/DataPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
2 changes: 1 addition & 1 deletion LiteDB/Engine/Pages/IndexPage.cs
Original file line number Diff line number Diff line change
Expand Up @@ -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);
}

/// <summary>
Expand Down
8 changes: 4 additions & 4 deletions LiteDB/LiteDB.csproj
Original file line number Diff line number Diff line change
Expand Up @@ -2,17 +2,17 @@

<PropertyGroup>
<TargetFrameworks>net45;netstandard1.3;netstandard2.0</TargetFrameworks>
<AssemblyVersion>5.0.2</AssemblyVersion>
<FileVersion>5.0.2</FileVersion>
<VersionPrefix>5.0.2</VersionPrefix>
<AssemblyVersion>5.0.3</AssemblyVersion>
<FileVersion>5.0.3</FileVersion>
<VersionPrefix>5.0.3</VersionPrefix>
<Authors>Maurício David</Authors>
<Product>LiteDB</Product>
<Description>LiteDB - A lightweight embedded .NET NoSQL document store in a single datafile</Description>
<Copyright>MIT</Copyright>
<NeutralLanguage>en-US</NeutralLanguage>
<Title>LiteDB</Title>
<PackageId>LiteDB</PackageId>
<PackageVersion>5.0.2</PackageVersion>
<PackageVersion>5.0.3</PackageVersion>
<PackageTags>database nosql embedded</PackageTags>
<PackageIcon>icon_64x64.png</PackageIcon>
<PackageLicenseFile>LICENSE</PackageLicenseFile>
Expand Down
14 changes: 14 additions & 0 deletions LiteDB/Utils/LiteException.cs
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
using LiteDB.Engine;
using System;
using System.Reflection;
using System.Text;
using System.Threading.Tasks;
using static LiteDB.Constants;

Expand Down Expand Up @@ -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
}
}

0 comments on commit 48957dd

Please sign in to comment.