How to catch sqlite3.open() errors in Lua - sqlite

According to the docs (http://luasqlite.luaforge.net/lsqlite3.html#sqlite3.open)
In case of an error, the function returns nil, an error code and an
error message.
But I always get the same results no matter if I provide a valid or invalid SQLite file. In fact, if I provide an inexistent file or an invalid path I still get the same results. For example:
db, code, msg = sqlite3.open("foo"))
print(db) -- sqlite database (0x7f9ab1628598)
print(code) -- nil
print(msg) -- nil
How can I catch these errors?

sqlite3.open creates a file if it does not exist. So, providing an inexistent file is not an error.
Providing an invalid path should be an error. Calling sqlite3.open("/foo/bar") will probably give you an error.
Another kind of error is a permission error. Calling sqlite3.open("/foo") if you're running some kind of Unix should give you a permission denied error.

Related

Is there an alternative to save_kable() in R?

I cannot use save_kable() to save tables created with knitr::kable() and knitr::kableExtra as images. It looks like this is due to PhantomJS being blocked by admins. Is there another function that could help me save them? This is the error i get:
Error in process_initialize(self, private, command, args, stdin, stdout, …: ! Native call to processx_exec failed Caused by error in
chain_call(c_processx_exec, command, c(command, args), pty, pty_options, …: ! create process
'C:\Users\user1\AppData\Roaming/PhantomJS/phantomjs.exe' (system error
1260, This program is blocked due to group policy. Contact the systems responsible person for more information. )
#win/processx.c:1040 (processx_exec)
PD: I translated to English the message that comes after "system error 1260...".

Transformation failed BizTalk

I have a map with a C# script in Script functoid to convert a date in dd/MM/yyyy format to yyyy-MM-dd format:
Here is the script I use in my functoid :
public string CheckDate(string inputDate)
{
if(String.IsNullOrEmpty(inputDate))
return "";
else
{
System.DateTime dt = System.Convert.ToDateTime(inputDate);
return dt.ToString("yyyy-MM-dd");
}
}
For an unknow reason this script works perfectly when I do a Test Map in VS, it also works on my DEV environment but when I deploy it on UAT I got this error message:
General Exception : Error encountered while executing the transform
XXX. Error:Transformation failed..
I already tried to use TryParse() or TryParseExact() but the mapping behavior is still the same. Work on DEV and Test Mapping but not on UAT.
EDIT
I catched the InnerException from Error:
System.Reflection.TargetInvocationException: Exception has been thrown by the target of an invocation. ---> System.FormatException: String was not recognized as a valid DateTime.
at System.DateTimeParse.Parse(String s, DateTimeFormatInfo dtfi, DateTimeStyles styles)
at System.Convert.ToDateTime(String value)
at System.Xml.Xsl.CompiledQuery.Script1.ConvertCompletedDate(String param)
So the issue is the input value but I only desn't work on UAT environment. This error is not thrown on DEV. I checked the .NET framework used and they are the same on both environment.
Can someone tells me how I can transform 18/11/2021 to a valid DateTime format ?
I finally figured out that my TryParseExact() wasn't good.
If you have these kind of error and the issue concern a DateTime, the answer is the #Shar1er80 's reply here

Error: "Decoding error (36) : Dictionary mismatch" using ZSTD decode on command line to decode a .ZST file

I am trying to decode a bunch of .ZST files which I do not know what the original file was so I can access them, however all of the .ZSTs return the exact same error and do not get decompressed. The error is Decoding error (36) : Dictionary mismatch. The command used is zstd -d * on Windows 10 x64 using ZSTD v1.4.4 for Win x64.
I have already tried CMD, PowerShell and Bash as different environments to run the command but all return the exact same error. I have tried decompressing a single individual file to see if it was a bulk-operation issue but it didn't work either. My last attempt was to Google for the error but I could not find anything.
Edit: After investigating a little further, I decided to try checking for the MIME types of my ZST files, some of them get returned as application/x-zstd while others get returned as application/octet-stream. I wonder if this could be the issue? Although neither MIME types work, both return the same error.
Does anyone know how I could fix this error and get to decompress my files?
Here is one of the ZST files for reference: https://mega.nz/#!eV0VTKBQ!WBW_pVIq8Tsn2Rrv3XKmt4DSAH7IHbHtaAuNB9uRTMQ

RobotFramework: How to catch ambiguous error in Run Keyword And Expect Error

I use robot framework at following environment.
Python 2.7.6
robotframework 2.8.7
Ubuntu 14.04.3 LTS
I test REST API, with keyword like this.
MyKeyword
Send Request -> Check Response Status Code -> Return Response content
And I use this keyword in negative case like followings.
Run Keyword And Expect Error 400 != 201 MyKeyword #args
In this case, if status code is 401, robot fails with this messages.
Expected error '400 != 201' but got '401 != 201'.
But I want to check that request will be rejected because of client reason,
so I wish status code were 40X.
How can I set Run Keyword And Expect Error ambiguous expected message?
I think you need to make use of wildcard characters as per the documentation - http://robotframework.org/robotframework/latest/libraries/BuiltIn.html#Run%20Keyword%20And%20Expect%20Error
I've never used it before but what I think you need change it to this:
Run Keyword And Expect Error 40? != 201 MyKeyword #args
Perhaps I've misunderstood the docs as I've never used this before though, in which case I would probably look to catch all errors:
Run Keyword And Expect Error * MyKeyword #args
It looks a little strange to me what you're doing though, should you not be using the variable the response result is returned in and checking against that? i.e. ${response} != 40?

Can you make R print more detailed error messages?

I've often been frustrated by R's cryptic error messages. I'm not talking about during an interactive session, I mean when you're running a script. Error messages don't print out line numbers, and it's often hard to trace the offending line, and the reason for the error (even if you can find the location).
Most recently my R script failed with the the incredibly insightful message: "Execution halted." The way I usually trace such errors is by putting a lot of print statements throughout the script -- but this is a pain. I sometimes have to go through the script line by line in an interactive session to find the error.
Does anyone have a better solution for how to make R error output more informative?
EDIT: Many R-debugging things work for interactive sessions. I'm looking for help on command-line scripts run through Rscript. I'm not in the middle of an R session when the error happens, I'm at the bash shell. I can't run "traceback()"
Try some of the suggestions in this post:
General suggestions for debugging in R
Specifically, findLineNum() and traceback()/setBreakpoint().
#Nathan Well add this line sink(stdout(), type="message") at the beginning of the script and you should get in console message both script content and output along with error message so you can see it as in interactive mode in the console. (you can then also redirect to a log file if you prefer keeping the console "clean")
Have a look at my package tryCatchLog (https://github.com/aryoda/tryCatchLog).
While it is impossible to improve the R error messages directly you can save a lot of time by identifying the exact code line of the error and have actual variables at the moment of the error stored in a dump for "post mortem" analysis!
The main advantages of the tryCatchLog function over tryCatch are
easy logging of errors, warnings and messages into a file or console
warnings do not stop the program execution (tryCatch stops the execution if you pass a warning handler function)
identifies the source of errors and warnings by logging a stack trace with a reference to the source file name and line number (since traceback does not contain the full stack trace)
allows post-mortem analysis after errors by creating a dump file with all variables of the global environment (workspace) and each function called (via dump.frames) - very helpful for batch jobs that you cannot debug on the server directly to reproduce the error!
This will show a more detailed traceback, but not the line number:
options(error = function() {traceback(2, max.lines=100); if(!interactive()) quit(save="no", status=1, runLast=T)})
One way inside a script to get more info on where the error occurred is to redirect R message to the same stream as errors :
sink(stdout(), type="message")
This way you get both messages and errors in the same output so you see which line raised the error...

Resources