Skip to content

Conversation

@yueyinqiu
Copy link
Collaborator

No description provided.

@yueyinqiu
Copy link
Collaborator Author

yueyinqiu commented Mar 10, 2025

Edit: Resolved by removing the null check here: https://github.com/magiccodingman/Magic.IndexedDb/pull/59/files#diff-0132de8e88774210aad5024d05d38dc329352599e5269017d87ee2c3ce071986L76


Hmm... Have I done something wrong? It throws an exception:

using Magic.IndexedDb;
using Magic.IndexedDb.Helpers;
using Microsoft.AspNetCore.Components;
using System.Text.Json;

namespace E2eTestWebApp.TestPages;

[Route("/WhereTest")]
public class WhereTestPage(IMagicDbFactory magic) : TestPageBase
{
    [MagicTable("Records", null)]
    private class Record
    {
        [MagicPrimaryKey("Id")]
        public int Id { get; set; }

        public int Int32Field { get; set; }
    }

    public async Task<string> Where1()
    {
        var database = await magic.OpenAsync(new DbStore()
        {
            Name = "Where.Where1",
            Version = 1,
            StoreSchemas = [SchemaHelper.GetStoreSchema(typeof(Record))]
        });
        await database.AddAsync<Record, int>(new Record()
        {
            Id = 1,
            Int32Field = 1
        });
        await database.AddAsync<Record, int>(new Record()
        {
            Id = 2,
            Int32Field = 2
        });
        await database.AddAsync<Record, int>(new Record()
        {
            Id = 3,
            Int32Field = 3
        });
        var result = await database
            .Where<Record>(x => x.Int32Field < 2)
            .ToListAsync();
        return JsonSerializer.Serialize(result.Select(x => x.Id));
    }
}
System.ArgumentNullException: Object cannot be null (Parameter 'value')
   at Magic.IndexedDb.Helpers.MagicSerializationHelper.SerializeObject[T](T value, MagicJsonSerializationSettings settings) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Helpers\MagicSerializationHelper.cs:line 63
   at Magic.IndexedDb.Models.TypedArgument`1.SerializeToJsonString(MagicJsonSerializationSettings settings) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Models\TypedArgument.cs:line 33
   at Magic.IndexedDb.Helpers.MagicSerializationHelper.<>c__DisplayClass1_0.<SerializeObjectsToString>b__0(ITypedArgument arg) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Helpers\MagicSerializationHelper.cs:line 23
   at System.Linq.Enumerable.ArraySelectIterator`2.Fill(ReadOnlySpan`1 source, Span`1 destination, Func`2 func)
   at System.Linq.Enumerable.ArraySelectIterator`2.ToArray()
   at Magic.IndexedDb.Helpers.MagicSerializationHelper.SerializeObjectsToString(ITypedArgument[] objs, MagicJsonSerializationSettings settings) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Helpers\MagicSerializationHelper.cs:line 23
   at Magic.IndexedDb.Extensions.MagicJsInvoke.TrueMagicStreamJsAsync[T](String functionName, CancellationToken token, Boolean isVoid, ITypedArgument[] args) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 30
   at Magic.IndexedDb.Extensions.MagicJsInvoke.MagicStreamJsAsync[T](String functionName, CancellationToken token, ITypedArgument[] args) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Extensions\MagicJsInvoke.cs:line 24
   at Magic.IndexedDb.IndexedDbManager.CallJsAsync[T](String functionName, CancellationToken token, ITypedArgument[] args) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\IndexDbManager.cs:line 573
   at Magic.IndexedDb.IndexedDbManager.WhereV2Async[T](String storeName, List`1 jsonQuery, MagicQuery`1 query, CancellationToken cancellationToken) in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\IndexDbManager.cs:line 250
   at Magic.IndexedDb.Models.MagicQuery`1.ToListAsync() in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\Magic.IndexedDb\Models\MagicQuery.cs:line 129
   at E2eTestWebApp.TestPages.WhereTestPage.Where1() in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\E2eTestWebApp\TestPages\WhereTestPage.cs:line 43
   at E2eTestWebApp.TestPages.TestPageBase.RunAsync() in C:\Users\yueyi\Documents\MyPersistentFiles\Projects\Magic.IndexedDb\Magic.IndexedDb\E2eTestWebApp\TestPages\TestPageBase.razor.cs:line 32

By the way, the steps to debug the test in visual studio:

  1. run E2eTestWebApp in debug mode (not E2eTest)
  2. in any browser, open http://localhost:XXXX/WhereTest
  3. enter Where1 in the left input
  4. press the left button, and WhereTestPage.Where1 will be executed

(Note the database deletion for unit test is done in E2eTest. When running E2eTestWebApp, it won't be automatically deleted, and primary key conflicts may occur.)

However in this case the debugger does not break at the exception... I don't why...

@yueyinqiu
Copy link
Collaborator Author

yueyinqiu commented Mar 10, 2025

By the way, it seems that we are regarding exceptions/errors from JavaScript as a normal result.

@yueyinqiu yueyinqiu marked this pull request as ready for review March 10, 2025 07:52
@magiccodingman magiccodingman merged commit 61c05b9 into magiccodingman:master Mar 10, 2025
@yueyinqiu yueyinqiu deleted the tests branch March 19, 2025 05:03
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants