Why does pyqgis not give error or warning, when opening project with invalid file path - qgis

I have a stand alone script, that opens a QGIS project file in order to extract details.
I accidentally moved a file and the script broke. Below is the interesting part.
QgsApplication.setPrefixPath("/usr", True)
project = QgsProject.instance()
qgs = QgsApplication([], False)
qgs.initQgis()
project.read('/home/jdoe/textproj.qgz')
# invalid path, but does not fail or warn in any way
print(project)
# prints: <QgsProject:'/home/jdoe/textproj.qgz'(singleton instance)>
# no indication of any problems with loading file
Question 1 - Why no error?
I think everyone would expect it to fail (throwing an exception). Is there any good reason for it to behave different than failing?
Question 2 - How to properly load a project from a file?
Is there anything in my code that that is is using the library differently that intended, which may partly explain why I got no errors?
Question 3 - How do I make sure it fails?
Of course I could write my own assertion to test if the path does point to a file. But I guess there could be other ways in which reading/loading a project file could fail. So what is the proper way of catching this right away?

Related

error in process sentinel: Could not start nREPL server: java.lang.NumberFormatException: Invalid number

I've looked at all of the similar questions on stack overflow. This one is different enough to warrant a separate question. Basically, I can't start a repl server because I get the error below. It's been pointed out that this is typically a dependency issue, but I'm updated, to my knowledge. What am I getting wrong here? Here's the full error:
error in process sentinel: Could not start nREPL server: java.lang.NumberFormatException: Invalid number: 0.8.3
at clojure.lang.LispReader.readNumber (LispReader.java:352)
clojure.lang.LispReader.read (LispReader.java:278)
clojure.lang.LispReader.readDelimitedList (LispReader.java:1398)
clojure.lang.LispReader$VectorReader.invoke (LispReader.java:1347)
clojure.lang.LispReader.read (LispReader.java:285)
clojure.lang.LispReader.read (LispReader.java:216)
clojure.lang.LispReader.read (LispReader.java:205)
clojure.lang.RT.readString (RT.java:1878)
clojure.lang.RT.readString (RT.java:1873)
clojure.core$read_string.invokeStatic (core.clj:3815)
clojure.core$read_string.invoke (core.clj:3805)
clojure.core$mapv$fn__8445.invoke (core.clj:6912)
clojure.core.protocols$fn__8159.invokeStatic (protocols.clj:168)
clojure.core.protocols/fn (protocols.clj:124)
clojure.core.protocols$fn__8114$G__8109__8123.invoke (protocols.clj:19)
clojure.core.protocols$seq_reduce.invokeStatic (protocols.clj:31)
clojure.core.protocols$fn__8146.invokeStatic (protocols.clj:75)
clojure.core.protocols/fn (protocols.clj:75)
clojure.core.protocols$fn__8088$G__8083__8101.invoke (protocols.clj:13)
clojure.core$reduce.invokeStatic (core.clj:6828)
clojure.core$mapv.invokeStatic (core.clj:6903)
clojure.core$mapv.invoke (core.clj:6903)
leiningen.update_in$parse_args.invokeStatic (update_in.clj:13)
leiningen.update_in$parse_args.invoke (update_in.clj:9)
leiningen.update_in$update_in.invokeStatic (update_in.clj:36)
leiningen.update_in$update_in.doInvoke (update_in.clj:24)
clojure.lang.RestFn.applyTo (RestFn.java:146)
clojure.lang.Var.applyTo (Var.java:705)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$apply.invoke (core.clj:660)
leiningen.core.main$partial_task$fn__7331.doInvoke (main.clj:284)
clojure.lang.RestFn.applyTo (RestFn.java:139)
clojure.lang.AFunction$1.doInvoke (AFunction.java:31)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.core$apply.invokeStatic (core.clj:667)
clojure.core$apply.invoke (core.clj:660)
leiningen.core.main$apply_task.invokeStatic (main.clj:334)
leiningen.core.main$apply_task.invoke (main.clj:320)
leiningen.core.main$resolve_and_apply.invokeStatic (main.clj:343)
leiningen.core.main$resolve_and_apply.invoke (main.clj:336)
leiningen.core.main$_main$fn__7420.invoke (main.clj:453)
leiningen.core.main$_main.invokeStatic (main.clj:442)
leiningen.core.main$_main.doInvoke (main.clj:439)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.core$apply.invokeStatic (core.clj:665)
clojure.main$main_opt.invokeStatic (main.clj:514)
clojure.main$main_opt.invoke (main.clj:510)
clojure.main$main.invokeStatic (main.clj:664)
clojure.main$main.doInvoke (main.clj:616)
clojure.lang.RestFn.applyTo (RestFn.java:137)
clojure.lang.Var.applyTo (Var.java:705)
clojure.main.main (main.java:40)
EDIT:
So I've gotten farther on this problem and I think I'm down to the last little issue or two. The file that is being pulled that causes the java.lang.NumberFormatException is cider.el which you can finder in your emacs.emacs.d\elpa\cider-[VERSION NUMBER, in my case 20210104.915]. You open your cider.el file and on line 392/393, in this version, you'll find:
(cider-add-to-alist 'cider-jack-in-dependencies
"nrepl/nrepl" "0.8.3")
So changing this line, recompiling it, and reloading emacs gets the number throwing the java.lang.NumberFormatException to change to whatever I changed it to (recompile by using byte-compile-file, hitting enter, then passing it the address of the document). Adding another set of double quotes gets a null value error of sorts (obviously) and doing any type of backslashing for exceptions and sort doesn't seem to solve the issue. So, since the few related posts (though with much less detail) seem to hint at changing the version number, I'm going to have to assume that I have to do that. What version number would work best here?
TEMP SOLUTION SO FAR:
start a repl with "lein repl" in command line and connect to it manually using the connect command "cider-connect" and specifying the localhost (I started the repl in same directory as project and it detected it easily). This is not good enough for me as a permanent solution but gets me up and going temporarily until a better solution is found.
PERMANENT SOLUTION:
see below
Look at your dependencies. I had an issue where my java jdk was basically broken (java's fault, not mine, in so far as the code is concerned). I ended up using the latest OpenJDK (number 15). That worked. If you get lots of java specific type errors and those errors change with the versions that you're using, then consider updating your java jdk. I was using LTE versions before and the latest fixed it.

Dymola error message when translating: "unknown internal error in Dymola"

I have problems translating Modelica models with Dymola 2020: When I try to translate the models, the following error message appears:
"unknown internal error in Dymola".
The model was translating and simulating a couple of days ago, and the same model still runs on the computer of other colleagues. I didn't change the compiler in between nor the Dymola version. I've also restarted the computer but the problem persists.
Also, other models are still translating, so not all models are affected by this error.
Does anyone have a clue how to debug this error? Thank you very much for all hints!
The most likely explanation would be some weird setting of some flag.
You can see if you have any odd settings of normal flags by:
Dymola 2020: Edit>Options>General>Flags... Check "Non-default"
Dymola 2020x: Tools>Options>General>Flags... Check "Non-default"
(If it is a non-Boolean setting it is a bit messier.)
That is assuming it is really the same model and there is no difference in any model in the path (including working directory).
Frankly speaking, if you get "unknown internal error in Dymola" you should report it to technical support at Dassault Systèmes (through your reseller), and let them debug it.
It is not your job to debug such errors.
Have you tried to delete the content from the working directory (WD)?
Sometimes there are artifacts, which mess up the compilation of a specific model.
You can check where it is, using the
GUI, File -> Working Directory -> Copy Path and paste it in the Explorer
Command line typing cd, which returns the path to the WD
Then make sure that there are no important files in the WD (usually .mo files) and finally delete the full content of the directory.
Note: You should ensure that the WD is a local path (otherwise performance can take a serious hit). Besides that it is usually a good idea to have the WD separated form the directory where models are stored.

Libmbed.a needed by '.../freedomboard_servo.elf'

I was going through the example of FRDM-KL25Z library in MATLAB Simulink and having some problems when deploying it to the board.
1) Most of the H files are missing in the directory during (compiling?) and was FIXED by downloading individually from website.
2) After the H files are fixed, MATLAB prompt me another error stating FILE_DIR/TOOLCHAIN_GCC_ARM/libmbed.a' needed by ".../freedom_board_servo.elf'
I'm quite new to this field so was hoping someone can guide me through these errors as I have been stuck here doing nothing for few days fixing errors and errors.
Thanks.libmbed.a ERROR
Hi all the problem is fixed by changing the directory of the file.
During installation MATLAB have named the directory wrongly "8e73be2a2ac1" was supposed to be named to "mbed-8e73be2a2ac1".

Error using matlab.io.fits.openFile - cannot open FITS files

I am running a code that uses the fitsread function to open my fits movies and analyse them. It was working perfectly fine until about a week ago, when, without me doing anything, it started giving the following error whenever I try to run it:
Error using matlab.io.fits.openFile (line 48)
Unable to open file. File might be corrupt or filename might have unsupported
characters.
Error in fitsread>read_image_hdu (line 412)
fptr = fits.openFile(info.Filename);
Error in fitsread (line 125)
data = read_image_hdu(info,1,raw,pixelRegion);
I have tried manually checking the properties of such files using the fitsinfo function and nothing was wrong with the files themselves. I have also tried to re-set the default MATLAB path, delete them from the working folder and re-download them from a central University server where they were originally stored upon acquisition on a microscope, but it didn't help either. A collaborator has tried running the same code on his machine and it works well. I get this same error on both MATLAB versions R2011b and R2015b. It originally used to work on R2011b with the same files.
Thanks in advance to whoever will be able to help!

Why would LayoutObjectNames return an empty string in FileMaker 14?

I'm seeing some very strange behavior with FileMaker 14. I'm using LayoutObjectNames for some required functionality. On the development system it's working fine. It returns the list of named objects on the layout.
I close the file, zip it up and send it to the client, and that required functionality isn't working. He sends the file back and I open it and get a data viewer up. The function returns nothing. I go into layout mode and confirm that there are named objects on the layout.
The first time this happened and I tried recovering the file. In the recovered file it worked, so I assumed some corruption had happened on his end. I told him to trash the file I had given him and work with a new version I supplied. The problem came up again.
This morning he sent me the oldest version that the problem manifested in. I confirmed the problem, tried recovering it again, but this time it didn't fix the problem.
I'm at a loss. It works in the version I send him, doesn't on his system. We're both using FileMaker 14, although I'm using Advanced. My next step will be to work from a served file instead of a local one, but I have never seen this type of behavior in FileMaker. Has anyone seen anything similar? Any ideas on a fix? I'm almost ready to just scrap the file and build it again from scratch since we're not too far into the project.
Thanks, Chuck
There is a known issue with the Get (FileName) function when the file name contains dots (other that the one before the extension). I will amend my answer later with more details and a possible solution (I have to look it up).
Here's a quote from 2008:
This is a known issue. It affects not only the ValueListItems()
function, but any function that requires the file name. The solution
is to include the file extension explicitly in the file name. This
works even if you use Get (FileName) to return the file name
dynamically:
ValueListItems ( Get ( FileName ) & ".fp7" ; "MyValueList" )
Of course, this is not required if you take care not to use period
when naming your files.
http://fmforums.com/forums/topic/60368-fm-bug-with-valuelistitems-function/?do=findComment&comment=285448
Apparently the issue is still with us - I wonder if the solution is still the same (I cannot test this at the moment).