Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Internal ObjectBox exceptions are not reported correctly #1

Closed
nalenz-objectbox opened this issue Sep 3, 2019 · 9 comments
Closed
Assignees

Comments

@nalenz-objectbox
Copy link
Contributor

nalenz-objectbox commented Sep 3, 2019

Operating system: Ubuntu 16.04 [to be confirmed for other OSs]
Dart version: 2.4.1

When trying to call ObjectBox functions with e.g. invalid parameters, normally the error should be reported on the command line as well as being reflected as an error code retrieved from obx_last_error_code. As an example, try creating an entity with ID -1 (@Entity(id: -1, uid: 1)), which is illegal in ObjectBox. Instead of seeing a meaningful message, the following is output, in other cases with the OBX_ERROR_NO_ERROR_INFO error code:

001-10:36:16.1248 [ERROR] Cannot handle thrown exception, no ptr

After some investigation, it became obvious that this issue is due to this problem in the Dart FFI, i.e. something rather fundamental in C++.

@greenrobot
Copy link
Member

From dart-lang/sdk#38141 (comment):

Flutter may not have this issue, but if they do, they (and other embedders) need to address it separately.

Once #9 is done, we should test this on Flutter and report to the Flutter project if required.

vaind pushed a commit to vaind/objectbox-dart that referenced this issue Oct 17, 2019
id-array FFI struct & TestEnv
@vaind
Copy link
Collaborator

vaind commented Nov 18, 2019

works with dart 2.6(.1)

added a test case in 04e1ae0

@vaind vaind closed this as completed Nov 18, 2019
@vaind
Copy link
Collaborator

vaind commented Jan 24, 2021

Turns out this doesn't work on Flutter for Linux (desktop), I've filed an issue: flutter/flutter#74599

@greenrobot
Copy link
Member

Since our original issue was closed ("fixed and then reverted"), the current one to watch is flutter/flutter#66575. Is there any info we could provide to speed this up on the Flutter side? E.g. a generalized test case?

They specifically mention Linux as the broken platform. Do Windows and macOS do not expose the behavior?

Could we get around the problem by statically linked libs, e.g. for Linux?

@vaind
Copy link
Collaborator

vaind commented May 5, 2021

The issue is specific to the Flutter linux build.

A statically linked libstdc++ doesn't help, still crashes during exception throw - we have a test case exactly for that in basics_test.dart, can be run as ~/lib/flutter/bin/dart run ./test/basics_test.dart.

For completeness, the usual libobjectbox.so dependencies and the ones with static libstdc++ linking:

$ ldd /usr/lib/libobjectbox.so 
        linux-vdso.so.1 (0x00007ffd00739000)
        libstdc++.so.6 => /usr/lib/libstdc++.so.6 (0x00007f34c2459000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007f34c2314000)
        libgcc_s.so.1 => /usr/lib/libgcc_s.so.1 (0x00007f34c22fa000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007f34c22d9000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007f34c210c000)
        /usr/lib64/ld-linux-x86-64.so.2 (0x00007f34c2997000)
$ ldd /usr/lib/libobjectbox.so 
        linux-vdso.so.1 (0x00007ffdb2995000)
        libm.so.6 => /usr/lib/libm.so.6 (0x00007ffa6c6de000)
        libpthread.so.0 => /usr/lib/libpthread.so.0 (0x00007ffa6c6bd000)
        libc.so.6 => /usr/lib/libc.so.6 (0x00007ffa6c4f0000)
        /usr/lib64/ld-linux-x86-64.so.2 (0x00007ffa6cff0000)

@vaind vaind added the on-hold Blocked by some other issue or a lack of information/ideas how to proceed. label May 5, 2021
@greenrobot
Copy link
Member

Not for now; has time for later: can we have fully static lib, not just libstdc++?

@vaind
Copy link
Collaborator

vaind commented May 6, 2021

can we have fully static lib, not just libstdc++?

not a shared library AFAICT.

@greenrobot-team
Copy link
Member

greenrobot-team commented Jul 5, 2022

Check if this is still an issue (e.g. the linked Flutter issue is closed). Test our Flutter example app on Linux.

E.g. modify objectbox/example/flutter/objectbox_demo_relations/lib/objectbox.dart to put with negative ID:

task = Task(text, id: -100);

@greenrobot-team
Copy link
Member

greenrobot-team commented Feb 28, 2024

OK, finally confirmed this is fixed. Tested with Flutter 3.19, but this was probably fixed as early as August 2021.

Exception is thrown as expected:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Invalid argument(s): object put failed: ID is higher or equal to internal ID sequence: 18446744073709551516 (vs. 4). Use ID 0 (zero) to insert new entities. (OBX_ERROR code 10002)
#0      ObjectBoxNativeError.throwMapped (package:objectbox/src/native/bindings/helpers.dart:76:9)
#1      throwLatestNativeError (package:objectbox/src/native/bindings/helpers.dart:54:48)
#2      Box._handlePutObjectResult (package:objectbox/src/native/box.dart:342:22)
#3      Box._put (package:objectbox/src/native/box.dart:252:10)
#4      Box.put.<anonymous closure> (package:objectbox/src/native/box.dart:95:53)
#5      Store._runInTransaction (package:objectbox/src/native/store.dart:776:24)
#6      InternalStoreAccess.runInTransaction (package:objectbox/src/native/store.dart:894:13)
#7      Box.put (package:objectbox/src/native/box.dart:94:34)
#8      Box._putAsyncCallback (package:objectbox/src/native/box.dart:103:22)
#9      _RunAsyncIsolateConfig.runCallback (package:objectbox/src/native/store.dart:959:51)
#10     Store._callFunctionWithStoreInIsolate (package:objectbox/src/native/store.dart:663:44)
#11     _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:300:17)
#12     _RawReceivePort._handleMessage (dart:isolate-patch/isolate_patch.dart:184:12)

@greenrobot-team greenrobot-team removed the on-hold Blocked by some other issue or a lack of information/ideas how to proceed. label Feb 28, 2024
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

No branches or pull requests

4 participants