why is dart's assert method is not working? - dart

Dart's assert function is not working for me for some reason.
It wasn't firing on my system
Dart VM version: 2.7.0 (Fri Dec 6 16:26:51 2019 +0100) on "windows_x64"
It isn't working on dartpad aswell.
Please look at this dartpad https://dartpad.dev/5352f91de86a0b3c58fdf6a8fb64a081.

It appears that assert statements are disable in dartpad since July 2019, you can check the GitHub issue here https://github.com/dart-lang/dart-pad/issues/310#issuecomment-514068279

This wasn't specific to dartpad as it wasn't running on my machine as well on dart 2.7.0.
I was able to run it with the flag --enable-asserts
dart --enable-asserts lib\main.dart
Note:
The flag must be passed as dart --enable-asserts lib\main.dart but not dart lib\main.dart --enable-asserts as the second approach implies this flag is meant for lib\main.dart and not dart.

If you are running brief Dart programs often from the command line to test ideas, it's worth adding the following line to your .bash_profile (or similar for other shells):
alias dart="dart --enable-asserts"

assert is not working on dartpad.dev either replit.com. I test it on 13 Oct 2021. So I used IntelliJ IDEA to work with assert and its working fine.

Related

How can I jit-compile a program that runs in a loop?

I have a web listener written in dart. I want to start it quicker, thats how I found https://dart.dev/tools/dart-compile#jit-snapshot.
However, when I execute dart compile jit-snapshot server.dart it runs the code which will run forever and so I never get the server.jit file. When I close the web-listener after a couple seconds it works fine but thats not what i want to compile.
Dart SDK version: 2.19.0-424.0.dev (dev) (Wed Nov 23 07:45:20 2022 -0800) on "linux_arm64"
dart compile jit-snapshot server.dart
should: generate server.jit
does: run forever. When I cancel it with Ctrl+c the .jit file is not generated...
For best performance, use AOT compilation
dart compile aot-snapshot server.dart
or build an executable
dart compile exe server.dart

Issue while running dataflow

I am getting below error while running dataflow job. I am trying to update my existing beam version to 2.11.0 but I am getting below error at run time.
java.lang.IncompatibleClassChangeError: Class
org.apache.beam.model.pipeline.v1.RunnerApi$StandardPTransforms$Primitives
does not implement the requested interface
com.google.protobuf.ProtocolMessageEnum at
org.apache.beam.runners.core.construction.BeamUrns.getUrn(BeamUrns.java:27)
at
org.apache.beam.runners.core.construction.PTransformTranslation.(PTransformTranslation.java:58)
at
org.apache.beam.runners.core.construction.UnconsumedReads$1.visitValue(UnconsumedReads.java:49)
at
org.apache.beam.sdk.runners.TransformHierarchy$Node.visit(TransformHierarchy.java:666)
at
org.apache.beam.sdk.runners.TransformHierarchy$Node.visit(TransformHierarchy.java:649)
at
org.apache.beam.sdk.runners.TransformHierarchy$Node.visit(TransformHierarchy.java:649)
at
org.apache.beam.sdk.runners.TransformHierarchy$Node.visit(TransformHierarchy.java:649)
at
org.apache.beam.sdk.runners.TransformHierarchy$Node.access$600(TransformHierarchy.java:311)
at
org.apache.beam.sdk.runners.TransformHierarchy.visit(TransformHierarchy.java:245)
at
org.apache.beam.sdk.Pipeline.traverseTopologically(Pipeline.java:458)
at
org.apache.beam.runners.core.construction.UnconsumedReads.ensureAllReadsConsumed(UnconsumedReads.java:40)
at
org.apache.beam.runners.dataflow.DataflowRunner.replaceTransforms(DataflowRunner.java:868)
at
org.apache.beam.runners.dataflow.DataflowRunner.run(DataflowRunner.java:660)
at
org.apache.beam.runners.dataflow.DataflowRunner.run(DataflowRunner.java:173)
at org.apache.beam.sdk.Pipeline.run(Pipeline.java:313) at
org.apache.beam.sdk.Pipeline.run(Pipeline.java:299)
This usually means that the version of com.google.protobuf:protobuf-java that Beam was built with does not match the version at runtime. Does your pipeline code also depend on protocol buffers?
UPDATE: I have filed https://issues.apache.org/jira/browse/BEAM-6839 to track this. It is not expected.
I don't have enough rep to leave a comment, but I ran into this issue and later figured out that my problem was that I had different beam versions in my pom.xml. Some had 2.19 and some had 2.20.
I would do a quick search of your versions in the pom or gradle file to make sure they are all the same.
This may be caused by incompatible dependencies. I successfully upgraded beam from 2.2.0 to 2.20.0 by upgrading the dependencies at the same time.
beam.version: 2.20.0
guava.version: 29.0-jre
bigquery.version: v2-rev20191211-1.30.9
google-api-client.version: 1.30.9
google-http-client.version: 1.34.0
pubsub.version: v1-rev20200312-1.30.9

Lua version in ZeroBraneStudio vs Torch

I am using ZeroBrane Studio as IDE to code deep learning. I have realized that the models I save when programming in the IDE (using Lua 5.1 as interpreter) do not load well when executing the same loading from Torch7. The same happens when learning from torch (./th code.lua) and then trying to load them inside the IDE. I get something like:
/opt/zbstudio/bin/linux/x64/lua: /home/dg/torch/install/share/lua/5.1/torch/File.lua:294: unknown object
Does anybody know how to check the lua version that torch is using? Any idea on how to workaround this?
Thanks!
update: It seems that I am indeed using the same Lua version (5.1) in both Torch and ZeroBrane. I still get different behaviour (one successful and the other crashing) when passing through torch.load().
To check the version of Lua that anything is running, you would usually print _VERSION. It's a global variable that stores the version of Lua (unless you overwrite it, of course).
print(_VERSION)
If this isn't available for some reason, they might state their version on their site (?)
Most command line tools on Linux understand the -v command line switch (for "version"). So do Lua and LuaJIT.
To figure out which interpreter is running a particular script, you can scan the arg table for the smallest (usually negative) index:
local exe, i = arg[ 0 ], -1
while arg[ i ] do
exe, i = arg[ i ], i-1
end
print( exe )
Or (on Linux) you can look into the /proc file system while your script is running:
ls -l /proc/4425/exe
(substitute 4425 with real process ID).
Judging from the error message the interpreter used in ZeroBrane Studio seems to be /opt/zbstudio/bin/linux/x64/lua in your case.
#siffiejoe: thanks for posing your question regarding versions, it gave me the correct directions to explore.
/opt/zbstudio/bin/linux/x64/lua version is LuaJIT 2.0.2
"lua" command alone points to /usr/bin/lua, and it is Lua 5.1.5
~/torch/install/share/lua/5.1 seemed to contain Lua 5.1
~/torch/install/bin/luajit is 2.1.0-alpha
So after realizing that terminal "th" is using LuaJit 2.1.0 all I had to do is create a user.lua in ZeroBrane and add the line "path.lua = "~/torch/install/bin/luajit". Now ZB is using the same luajit interpreter as th.
Thanks all for your suggestions.

jenkins chinese input arguments

I have one jenkins build project which has one string argument on Linux, but it cannot receive Chinese string argument correctly. e.g. I try to print it using echo ${sql}, sql is my argument variable, I inut "北京", but jenkins shows in console output is below:
echo '??'
How to solve this problem?
How up to date is your version of Jenkins?
There was a patch back in May 2013.
Also, unicode for the console was more recently resolved on Sept 27.
If your Jenkins runs on Ubuntu, note that it uses the system locale at JVM startup time.
Hope that helps.

dart:uri in generated Dart html pages does not run

With the latest version of dart (editor 24275) I keep getting an error re: dart:uri
This is placed in my built html:
import "dart:isolate" as FB;import "dart:uri" as MH;import "dart:json" as ............
Dart VM version: 0.5.20.4_r24275 (Fri Jun 21 05:02:35 2013) on "macos_ia32"
dart:uri is now in dart:core I recall.. but my html keeps getting built with this in it and so doesn't run in Chromium with the Dart VM
I've removed the out folder and rebuilt, does not resolve it.
Have you definitely removed all instances of import "dart:uri" from your code, whether they are stand alone Dart scripts or scripts embedded in HTML templates/components etc?
It's always good to run "Reanalyze Sources" too.
It sounds like you need to run pub update.

Resources