I'm working on school project, which requires to show some simple data from mysql database in browser. I've read, that SQLJocky doesn't work in browser so I decided to make it like server-client app and run db on server side (got inspiration here: https://dart-lang.github.io/server/codelab/). But it didn't work, failed in creating client api with message:
*in ShutdownIsolate: Unhandled exception:
IsolateSpawnException: Unable to spawn isolate: Unhandled exception:
Load Error for "package:sqljocky/sqljocky.dart": No mapping for 'sqljocky' package when resolving 'package:sqljocky/sqljocky.dart'.
#0 _asyncLoadErrorCallback (dart:_builtin:155)
#1 _asyncLoadError (dart:_builtin:566)
#2 _loadPackage (dart:_builtin:605)
#3 _loadData (dart:_builtin:637)
#4 _loadDataAsync (dart:_builtin:657)
#5 _loadScriptCallback (dart:_builtin:153)
#6 _handleLoaderReply (dart:_builtin:370)
#7 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)
'file:///home/alenka/dart-pokusy/server-side-app/one-hour-codelab/server/7-serve/lib/server/dbConnector.dart': error: line 1 pos 1: library handler failed
import 'package:sqljocky/sqljocky.dart';
^
#0 Isolate.spawnUri.<spawnUri_async_body> (dart:isolate-patch/isolate_patch.dart)
#1 _asyncErrorWrapperHelper.<anonymous closure> (dart:async-patch/async_patch.dart:34)
#2 _RootZone.runBinary (dart:async/zone.dart:1154)
#3 _Future._propagateToListeners.handleError (dart:async/future_impl.dart:579)
#4 _Future._propagateToListeners (dart:async/future_impl.dart:641)
#5 _Future._completeError (dart:async/future_impl.dart:432)
#6 _SyncCompleter._completeError (dart:async/future_impl.dart:56)
#7 _Completer.completeError (dart:async/future_impl.dart:27)
#8 Isolate._spawnCommon.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:439)
#9 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:148)*
Does anyone have idea how to solve this problem, or how to get data from db in browser differently?
Code added containing things from SQLJocky:
`import 'package:sqljocky/sqljocky.dart';
import 'dart:async';
...
#ApiMethod(path: 'connect')
Future<List<String>> dbConnect() async {
List<String> rows = [];
print('called dbConnect');
var pool = new ConnectionPool(
host: 'localhost',
port: 3306,
user: "root",
password: null,
db: 'project',
max: 5);
print('connection created');
var results = await pool.query('select * from User');
print('gonna write something from db');
results.forEach( (row){
print('Name: ${row[0]}, password: ${row[1]}');
rows.add('Name: ${row[0]}, password: ${row[1]}');
});
return rows;
}
`
Isolate your server side code and client side code into separates projects with their own pubspec.yaml.
I've found that sqljocky doesn't play nice with some of the client side libraries when both are in the pubspec.yaml.
Related
I have been trying to generate dart diagrams for my code but the below error:
C:\Users\Foldername\AppData\Local\Pub\Cache\bin>dart pub global run dcdg
C:\Users\Foldername\AppData\Local\Pub\Cache\bin\lib
Unhandled exception:
Bad state: Unable to find the context to C:\Users\Foldername\AppData\Local\Pub\Cache\bin\lib\.env.dart
#0 AnalysisContextCollectionImpl.contextFor (package:analyzer/src/dart/analysis/analysis_context_collection.dart:106:5)
#1 findClassElements (package:dcdg/src/find_class_elements.dart:46:39)
#2 main (file:///C:/Users/Foldername/AppData/Local/Pub/Cache/hosted/pub.dartlang.org/dcdg-4.0.1/bin/dcdg.dart:35:25)
#3 _delayEntrypointInvocation.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:295:32)
#4 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:192:12)
1- I have activated the package.
2- I have updated it to the latest.
3- Environment variables are correctly set.
I still don't understand why does it not allow me to create class diagrams for my code. Anyone has any answers?
I think that probably in your project are dependencies that use code-generation (with build_runner) like: freezed, auto_route, localizely or hive. Package dcdg at the moment (ver. 4.1.0) have issues for generating PlantUML file for such projects. If you want to use dcdg you need to refactor your code and remove such dependencies.
Here is github issue related to your case.
I'm building a program that use the Dart's AST library, and it works fine as long as I use the Dart interpreter to run the program (dart filename.dart).
Once I want to compile the program (dart compile filename.dart), the program can't load the file and I have this stacktrace:
#0 _PhysicalFile.readAsStringSync (package:analyzer/file_system/physical_file_system.dart:184)
#1 FolderBasedDartSdk.languageVersion (package:analyzer/src/dart/sdk/sdk.dart:400)
#2 FeatureSetProvider.build (package:analyzer/src/dart/analysis/feature_set_provider.dart:143)
#3 AnalysisDriver._createFileTracker (package:analyzer/src/dart/analysis/driver.dart:1500)
#4 new AnalysisDriver (package:analyzer/src/dart/analysis/driver.dart:291)
#5 ContextBuilder.buildDriver (package:analyzer/src/context/builder.dart:119)
#6 ContextBuilderImpl.createContext (package:analyzer/src/dart/analysis/context_builder.dart:94)
#7 new AnalysisContextCollectionImpl (package:analyzer/src/dart/analysis/analysis_context_collection.dart:55)
#8 _createAnalysisContext (package:analyzer/dart/analysis/utilities.dart:125)
#9 resolveFile (package:analyzer/dart/analysis/utilities.dart:115)
#10 main (package:DartProjects/dartprojects.dart:122)
#11 _startIsolate.<anonymous closure> (dart:isolate-patch/isolate_patch.dart:299)
#12 _RawReceivePortImpl._handleMessage (dart:isolate-patch/isolate_patch.dart:168)
I took a look at the source code to see where could be the error, and it seems that in package:analyzer/src/dart/sdk/sdk.dart it tries to get the langage version file, but instead of using the PATH to know where my dart sdk is, it tries to find it in my InteliJ folder, which fails. Also, I tried to run it on a freshly created VM, and it fails too.
Here is the code that produce this output:
import 'dart:io';
import 'package:analyzer/dart/analysis/utilities.dart';
import 'package:analyzer/dart/ast/ast.dart';
import 'package:analyzer/dart/ast/visitor.dart';
void main(List<String> arguments) async {
final fileName = Directory.current.path + r'\test.dart';
var source = null;
try {
source = await resolveFile(path: fileName);
} catch (e, s) {
print('${s}');
return;
}
}
Thanks for your help.
Not a good workaround.
Copy the "version" file from the Dart SDK folder to the root of your project.
The analyzer will take it and use it.
This will work if your compiled file is in the "bin" folder.
This is not a good workaround.
P.S.
This is called a hack.
My prestashop gives the following errors:
Fatal error: Uncaught Error: Call to a member function getProducts() on null in /var/www/html/minie.dk/public_html/modules/productsbundle/productsbundle.php:181 Stack trace: #0 /var/www/html/minie.dk/public_html/classes/Hook.php(591): ProductsBundle->hookActionCartSave(Array) #1 /var/www/html/minie.dk/public_html/classes/Hook.php(546): HookCore::coreCallHook(Object(ProductsBundle), 'hookactionCartS...', Array) #2 /var/www/html/minie.dk/public_html/classes/Cart.php(214): HookCore::exec('actionCartSave') #3 /var/www/html/minie.dk/public_html/classes/controller/FrontController.php(327): CartCore->update() #4 /var/www/html/minie.dk/public_html/classes/controller/Controller.php(170): FrontControllerCore->init() #5 /var/www/html/minie.dk/public_html/classes/Dispatcher.php(367): ControllerCore->run() #6 /var/www/html/minie.dk/public_html/index.php(28): DispatcherCore->dispatch() #7 {main} thrown in /var/www/html/minie.dk/public_html/modules/productsbundle/productsbundle.php on line 181
Can Anyone here see what the problem may be? And also, how to save it?
This problem is related to your 'productsbundle' module when a product is added to the customer's shopping cart.
I would suggest either to update this module to the latest version available or to disable it from your admin panel.
In the onBootstrap of my Application's Module.php I have registered a function onErrors on the EVENT_DISPATCH and EVENT_DISPATCH_ERROR events. In any of my models if I throw a custom error, Zend will catch it for me and in the onErrors function and I can handle the error (show an error page, return an error message as json, etc). This works fine except when an error is thrown in a function that's being used by Smarty. In that case I do still end up in the onErrors, but McvEvent->exception is NULL and I get this error:
Fatal error: Uncaught exception 'Application\Exception\InternalServerErrorException' in
/........../module/Smarty/src/Smarty/View/Renderer.php:90 Stack trace:
#0 /........../vendor/zendframework/zendframework/library/Zend/View/View.php(205):
Smarty\View\Renderer->render(Object(Zend\View\Model\ViewModel))
#1 /........../vendor/zendframework/zendframework/library/Zend/Mvc/View/Http/DefaultRenderingStrategy.php(102):
Zend\View\View->render(Object(Zend\View\Model\ViewModel))
#2 [internal function]:
Zend\Mvc\View\Http\DefaultRenderingStrategy->render(Object(Zend\Mvc\MvcEvent))
#3 /........../vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(468):
call_user_func(Array, Object(Zend\Mvc\MvcEvent))
#4 /........../vendor/zendframework/zendframework/library/Zend/EventManager/EventManager.php(207):
Zend\EventManager\EventManager->triggerListeners('render.error',
Object(Zend\Mvc\MvcEvent), Array)
#5 /.......... in
/........../module/Smarty/src/Smarty/View/Renderer.php on line 90
What's happening here? Why isn't Zend catching this error for me?
Is there a simple example of custom component in MDL Dart http://www.material-design-lite.pub using a data table or a list linked to a model changing over time?
I have the exception
Exception: Uncaught Error: RangeError: Index out of range: index should be less than 6: 6
Stack Trace:
#0 HtmlCollection.[] (dart:html:17296)
#1 _ChildrenElementList.[] (dart:html:10623)
#2 MaterialRepeat.insert.<insert_async_body> (package:mdl/src/template/components/MaterialRepeat.dart:148:55)
#3 Future.Future.microtask.<anonymous closure> (dart:async/future.dart:144)
#4 _microtaskLoop (dart:async/schedule_microtask.dart:43)
#5 _microtaskLoopEntry (dart:async/schedule_microtask.dart:52)
#6 _ScheduleImmediateHelper._handleMutation (dart:html:42503)
Using the custom ToDo sample when updating the items list