How to restart a dart server which file changes? - dart

I'm running a web server with dart, it starts by:
dart server.dart
When I modified the project files, I hope this server can be restarted automatically. Is there any way to do it? Or is there any useful tool can help?

Not natively in Dart until bug 3310 is implemented. There may well be external tools that will restart the command line when a file changes (open to other answers).

Just ran into this problem developing a dart server. For vscode IDE, following this stackoverflow suggestion I installed the Save and Run Ext extension and modified it for a dart command line program:
{
"saveAndRunExt": {
"commands": [
{
// "match": "\\.(css$|js$|html$)",
"match": ".dart$",
"isShellCommand": false,
"cmd": "workbench.action.debug.restart",
"isAsync": false
},
{
"match": ".dart$",
"isShellCommand": false,
"cmd": "dart.rerunLastTestDebugSession"
}
]
}
}
This will restart the server in debug mode and rerun the last test debug session if any dart file is saved. Both server and test debug sessions work.
Works great for me, at least on initial use of this extension.

Related

Debug Dockerized Flask app in VSCode not breaking on breakpoints

I followed this tutorial to set up debug in my VSCode.
My launch.json file is below.
{
// Use IntelliSense to learn about possible attributes.
// Hover to view descriptions of existing attributes.
// For more information, visit: https://go.microsoft.com/fwlink/?linkid=830387
"version": "0.2.0",
"configurations": [
{
"name": "Python: Remote Attach",
"type": "python",
"request": "attach",
"connect": {
"host": "localhost",
"port": 5678
},
"pathMappings": [
{
"localRoot": "${workspaceFolder}/server/project/views",
"remoteRoot": "/server/project/views"
}
]
}
]
}
My code does break on raised and user uncaught exceptions but it does not break on the breakpoints that I set. The code is reaching the breakpoints and I checked it using print statements, but my breakpoints are not working. VSCode debugger does seem to listen to my docker app (seen in the logs in screenshot) but not sure why it is not breaking at my breakpoints. However, it does give an error saying:
pydev debugger: unable to find translation for:
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/utils/assessments.py"
in ["/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views/",
"/home/vvarma9/DTNetworkRepos/ip2m-metrr/server/project/views"]
(please revise your path mappings).
Kindly help!
Make sure your local and remote paths are correct. You can check your remote path by logging into the container's terminal. There you can find the absolute path of your "app".
I also cannot tell where you ${workspaceFolder} is actually is. Could be DTNetworkRepos or ip2m-metrr. You will need to make sure you clarify the path.
Also it would help if you posted up your folder stucture, Docker file for the server project and docker compose for all your container projects. Docker file will explain your path on the remote server. Dockerfile & Docker-compose file will ensure us that you have the right cmd or entrypoint for your environment. It may not line up with the tutorial that you set up.

pm2 keep auto restarting on image upload

I am very close to release and while I was testing, I realized my api restarts on image upload, giving me 502 error.
I realized pm2 was restarting on image upload endpoint - since it is not logging any error on api side, it must have been server itself.
while investigating, I realized i had watch option to be true, so I set it to false and expecting all things to work again.
"apps": [
{
"name": "app",
"script": "src/index.js",
"instances": 1,
"autorestart": true,
"watch": false,
"time": true,
"env": {
"NODE_ENV": "production"
}
}
]
}
this is my ecosystem.config.json and my pm2 command is pm2 start ecosystem.config.json --no-daemon
well, pm2 still restarting on every image upload endpoint, giving me same error 502.
I am not physically storing images on my server, i simply save images to s3 buckets.. so image upload file change must be some kind of temp file... can anyone guide me to the right direction?
Thank you.
edit:
Just figured out this silent crash only happens in docker container.. feature works fine when server was ran locally. Still trying to debug it. Also could possibly be sharp image resizing crashing... unsure..
tried sharp.concurrency(1); sharp.cache(false); and setting UV_THREADPOOL_SIZE=1 but no luck
Fixed.
those who are having similar issue.
problem was actually on sharp image resizing library.
the older version library was not compatible with node:alpine.
updating the library to the latest one fixed the problem and the container does not crash anymore.

Mixed debugging (C#, C++) in VS Code via docker

We've recently moved our development from Visual Studio to VS Code. Our code solution contains .NET Core C# which hands calculations off to C++. In Visual Studio, we were able to seamlessly debug between C# and C++.
We initially moved to running the multi-project solution in a VM and using the remote development features of VS Code. We use two Launch configurations:
{
"name": "(gdb) Attach",
"type": "cppdbg",
"request": "attach",
"program": "/usr/share/dotnet/dotnet",
"processId": "${command:pickProcess}",
"additionalSOLibSearchPath": "${workspaceFolder}/src/build/Debug/Cpp/",
"MIMode": "gdb",
"setupCommands": [
{
"description": "Enable pretty-printing for gdb",
"text": "-enable-pretty-printing",
"ignoreFailures": true
}
]
},
{
"name": "Run C#",
"type": "coreclr",
"request": "launch",
// If you have changed target frameworks, make sure to update the program path.
"program": "${workspaceFolder}/src/AppProject/bin/Debug/netcoreapp2.2/AppProject.dll",
"args": [],
"cwd": "${workspaceFolder}/src/AppProject",
"stopAtEntry": false,
// Enable launching a web browser when ASP.NET Core starts. For more information: https://aka.ms/VSCode-CS-LaunchJson-WebBrowser
"env": {
"ASPNETCORE_ENVIRONMENT": "Development",
"EnvironmentName": "Development",
"LD_LIBRARY_PATH": "${workspaceFolder}/src/build/Release/Cpp/;$LD_LIBRARY_PATH"
},
"sourceFileMap": {
"/Views": "${workspaceFolder}/Views"
}
}
}
First running "Run C#" then running "(gdb) Attach" and selecting the dotnet process to attach to. This worked, allowing us to step down from C# into C++.
We've now moved to a Docker set up, where the source is mounted into a container with the build tools built in (as described in the VS Code docs). This is roughly our devcontainer.json:
{
"image": [custom image in a private code repository],
"forwardPorts": [various ports to serve web interfaces],
"runArgs": [
"--cap-add=SYS_PTRACE",
"--security-opt",
"seccomp=unconfined"
],
"extensions": [
"ms-vscode.cpptools",
"ms-vscode.cmake-tools",
"hbenl.vscode-test-explorer",
"derivitec-ltd.cmake-test-adapter",
"ms-dotnettools.csharp",
"fernandoescolar.vscode-solution-explorer",
"derivitec-ltd.vscode-dotnet-adapter"
],
"mounts": [
"source=${localEnv:HOME}/.gitconfig,target=/root/.gitconfig,type=bind,consistency=cached",
"source=${localEnv:HOME}/.ssh,target=/root/.ssh,type=bind,consistency=cached"
]
}
In this set up, we've been able to successfully debug C# and C++ code separately, but the above flow of running the C# project and attaching GDB after it does not work as expected. The C# process exits, while the "(gdb) Attach" call starts multiple processes which run into various exceptions at launch. I've pasted the full output to Pastebin.
Much of the advice I've found is confused due to:
legacy methods such as calling docker directly (omnisharp/omnisharp-vscode issue on debugging in docker)
alternative setups where source code is packaged into a docker container rather than mounted (VS Code docs for debugging .NET Core in docker)
alternative setups where build tools live in a docker container but VS Code communicates with the docker container via SSH rather than using the dev container approach recommended in the docs (Microsoft blog post on developing C++ with VS Code and docker)
C++ seemingly having special requirements for debugging, especially where docker is concerned
The runArgs description in the devcontainer.json reference:
For example, "runArgs": [ "--cap-add=SYS_PTRACE", "--security-opt", "seccomp=unconfined" ] allows ptrace based debuggers like C++ to work in the container.
VS Code docs suggesting that debugging should work exactly as it does natively when using remote development tools ("Debugging in a container" from VS Code docs)
How should I debug both C# and C++ running within a docker container using VS Code?

exiftool-vendored doesn't return when used in an electron app on Mac?

On Mac, when I run my app from WebStorm, exiftool-vendored works great. However, when I build my app (I use electron-builder) and install it on the same Mac, it never returns, even just trying to get the version:
exiftool.version().then(version => writeBreadcrumb('exif', version))
In other words, no error is raised, and the then is never executed when running an installed version of my app, though it works fine running my app from WebStorm (with cd build && electron .)
What am I doing wrong? Is there an example anywhere of how to use exiftool-vendored in an electron app?
You should take a look at what the docs say about making it work with Electron:
How do you make this work with electron?
Electron is notoriously brittle and buggy, and is not officially supported by this package. Although PhotoStructure uses this package within electron, there's a nontrivial amount of auxiliary support code specific to that project to make it work smoothly.
If you're still anxious to try, here are some things to keep in mind:
Note that this package will spawn exiftool external processes, which means the exiftool-vendored.pl and exiftool-vendored.exe packages should be included in your asarUnpack. SmartUnpack might work, but if it doesn't use a pattern like node_modules/{exiftool-vendored.*}/**/*.
If you're requiring exiftool-vendored from within a webview, you're gonna have a bad time. Many things won't work due to a lack of node compatibility within electron.
__dirname at runtime from within an asar package after webpacking will be invalid, so don't rely on that.
— https://github.com/photostructure/exiftool-vendored.js/wiki/FAQ#how-do-you-make-this-work-with-electron
Since I never found a way to get exiftool-vendored to work with electron on Mac, I accepted the above answer, as essentially a warning to steer clear of exiftool-vendored for electron on Mac.
This answer is included for completeness, for those of us who need exiftool in an electron app for both Mac and Windows:
I used node-exiftool with these settings added in package.json for electron-builder:
"build": {
...
"win": {
...
"extraResources": "exiftoolwin/**/*"
},
"mac": {
...
"extraResources": "exiftool/**/*"
}
}
In the root of my project, I added folders exiftoolwin and exiftool. In exiftoolwin, I put exiftool.exe which I obtained by following the Windows Stand-Alone Executable instructions here, and in my exiftool folder I put exiftool and lib which I obtained by extracting the full perl distribution on Mac, as described on the same page.
Then, in my .jsx (I'm using React):
import exiftool from 'node-exiftool';
const exiftoolFolderAndFile = process.platform === 'win32' ? 'exiftoolwin/exiftool.exe' : 'exiftool/exiftool';
const exiftoolPath = path.resolve(__dirname, '../..', exiftoolFolderAndFile);
const ep = new exiftool.ExiftoolProcess(exiftoolPath);
Then I just use ep as described here.
This is working for us:
add this dependency:
"exiftool-vendored": "^15.2.0",
Update package.json "build" section for mac ( not needed for windows as far as we can see )
"build": {
"mac": {
...
"asarUnpack": [
"node_modules/exiftool-vendored/**" ,
"node_modules/exiftool-vendored.pl/**"
]
}
}

debugging dart in visual studio code

I'm new to Dart/Visual studio code and have hit a wall setting up one of the predefined stagehand apps "web-angular".
I've installed the dart language support extension and created a new folder called c:\webdev\Angular_dart . From within the terminal in VSCode i ran "stagehand web-angular", then "pub get" then "pub global run webdev serve web:8888"
I'm able to see the default web page (a todo list) but when I hit F5 from within VSCode it gives me an error saying it can't see any of the files in my lib folder.
The first one it hits is..
web/main.dart:2:8: Error: Error when reading 'lib/app_component.template.dart': The system cannot find the file specified.
import 'package:Angular_Dart/app_component.template.dart' as ng;
it looks like my .packages file is setup correctly as my last line reads
Angular_Dart:lib/
And my launch.json configuration is
"name": "Dart",
"program": "web/main.dart",
"request": "launch",
"type": "dart"
Has anyone seen this?
Thanks in advance.
Right now it's simple. Use following configuration:
{
"name": "Dart",
"program": "web/index.html",
"request": "launch",
"type": "dart"
}
VS Code: 1.50.1
Dart SDK: 2.11.0-213.1.beta
Make sure "program" points to the index HTML file.
Edit: This answer is out of date, see theanurin's answer above or the Dart-Code v3.7 release notes.
The Dart VS Code extension doesn't currently have first-class support for web apps so unfortunately it's not as simple as just hitting F5 like for Flutter or CLI projects.
There are some relevant discussions here:
https://github.com/Dart-Code/Dart-Code/issues/386
https://github.com/dart-lang/build/issues/1025
The Flutter Devtools app is somewhat set up for this, and has VS Code tasks and launch configs to launch with webdev serve:
https://github.com/flutter/devtools/tree/master/packages/devtools/.vscode
The build config uses the Chrome Debugger for launching the browser, but has a preLaunchTask that runs webdev serve. It works, but the debugging isn't perfect, it's using source maps via the Chrome Debugger extension.

Resources