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

RDART-983: Refactor how we open dynamic library to give better error message #1614

Merged
merged 3 commits into from
Apr 3, 2024

Conversation

nielsenko
Copy link
Contributor

@nielsenko nielsenko commented Apr 2, 2024

This PR aims to give a better error message, if we fail to load the native shared library.

In the process It changes how we attempt to open it.

First of all it only tries one place when running under the flutter vm, which is the most common scenario. This is not only more correct, but it also improves the error message on failure by not referring to unrelated paths.

Secondly, it will report a hint to add realm package if it fails. It is an easy mistake to only add realm_dart. We have seen one example already in #1595.

Fix: #1595

Sample error messages

Dart script:

dart run bin/init_realm_dart.dart
Unhandled exception:
Realm error : Could not open librealm_dart.dylib. Tried:
- "librealm_dart.dylib"
- "/Users/kasper/.puro/shared/caches/e76c956498841e1ab458577d3892003e553e4f3c/dart-sdk/bin/librealm_dart.dylib"
/Users/kasper/Projects/mongodb/experiments/init_realm_dart/binary/macos/librealm_dart.dylib
Hint: Did you forget to run `dart run realm_dart install`?
#0      _openRealmLib.throwError (package:realm_dart/src/init.dart:71:5)
#1      _openRealmLib (package:realm_dart/src/init.dart:97:5)
#2      initRealm (package:realm_dart/src/init.dart:120:24)
...

Dart pre-compiled exe:

./bin/init_realm_dart.exe
Unhandled exception:
Realm error : Could not open librealm_dart.dylib. Tried:
- "librealm_dart.dylib"
- "/Users/kasper/Projects/mongodb/experiments/init_realm_dart/bin/librealm_dart.dylib"
- "/Users/kasper/Projects/mongodb/experiments/init_realm_dart/binary/macos/librealm_dart.dylib"
Hint: Did you forget to run `dart run realm_dart install`?
#0      _openRealmLib.throwError (package:realm_dart/src/init.dart:71)
#1      _openRealmLib (package:realm_dart/src/init.dart:97)
#2      initRealm (package:realm_dart/src/init.dart:120)

Flutter app:

[ERROR:flutter/runtime/dart_vm_initializer.cc(41)] Unhandled Exception: Realm error : Could not open realm_dart. Tried:
- "/Users/kasper/Library/Developer/CoreSimulator/Devices/FB6A66E7-50AF-4C35-8118-83EFE909C4D3/data/Containers/Bundle/Application/80555876-B519-4C9E-A280-5CD535D09A4B/Runner.app/Frameworks/realm_dart.framework/realm_dart"
Hint: Did you forget to add a dependency on the realm package?
#0      _openRealmLib.throwError (package:realm_dart/src/init.dart:71:5)
#1      _openRealmLib (package:realm_dart/src/init.dart:84:29)
#2      initRealm (package:realm_dart/src/init.dart:120:24)
...

@cla-bot cla-bot bot added the cla: yes label Apr 2, 2024
@nielsenko nielsenko changed the title Refactor how we open dynamic library to give better error message RDART-983: Refactor how we open dynamic library to give better error message Apr 2, 2024
Copy link

coveralls-official bot commented Apr 2, 2024

Pull Request Test Coverage Report for Build 8536025352

Warning: This coverage report may be inaccurate.

This pull request's base commit is no longer the HEAD commit of its target branch. This means it includes changes from outside the original pull request, including, potentially, unrelated coverage changes.

Details

  • 10 of 21 (47.62%) changed or added relevant lines in 1 file are covered.
  • No unchanged relevant lines lost coverage.
  • Overall coverage decreased (-0.07%) to 86.162%

Changes Missing Coverage Covered Lines Changed/Added Lines %
packages/realm_dart/lib/src/init.dart 10 21 47.62%
Totals Coverage Status
Change from base Build 8522416033: -0.07%
Covered Lines: 5834
Relevant Lines: 6771

💛 - Coveralls

@nielsenko nielsenko requested a review from elle-j April 2, 2024 16:20
@nielsenko nielsenko marked this pull request as ready for review April 2, 2024 16:20
Copy link
Contributor

@elle-j elle-j left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nice with improved error messages 🙂 Just have some small suggestions.

packages/realm_dart/lib/src/init.dart Show resolved Hide resolved
packages/realm_dart/lib/src/init.dart Show resolved Hide resolved
packages/realm_dart/lib/src/init.dart Outdated Show resolved Hide resolved
packages/realm_dart/lib/src/init.dart Show resolved Hide resolved
@nielsenko nielsenko merged commit 797d10d into main Apr 3, 2024
56 of 57 checks passed
@nielsenko nielsenko deleted the kn/refactor-dlopen branch April 3, 2024 09:30
papafe added a commit that referenced this pull request Apr 8, 2024
* main:
  RDART-996: Don't serialize backlinks (#1617)
  Update README.md (#1608)
  RDART-983: Refactor how we open dynamic library to give better error message (#1614)
  RDART-991: Rename Key enum (#1613)
  RDART-992: Handle Identifer expression as well (#1612)
  Add workflow_dispatch for development
  Common setup script (#1610)
  RDART-992: Const initializer evaluation is too simple (#1607)

# Conflicts:
#	CHANGELOG.md
@github-actions github-actions bot locked as resolved and limited conversation to collaborators May 3, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
Projects
None yet
Development

Successfully merging this pull request may close these issues.

Failed to load dynamic library 'librealm_dart.so'
2 participants