Fail404 option with hurl 1.2

Discuss any general programming issues here
Post Reply
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Fail404 option with hurl 1.2

Post by amyren »

After updating the hurl plugin from 1.1 to 1.2 I get a problem with one of my programs.

Here is the command used to get a file

Code: Select all

 DownloadFile(fil_dl2$, {File = deltakerfil2$, Fail404 = True, Adapter = "hurl"})
In this case the file does not (yet) exist on the server, and should not be downloaded.
Later in the script I do check for the filesize, and if the filesize is bigger than 1 the script will continue reading the file into a table.

Code: Select all

OpenFile(1, deltakerfil2$, #MODE_READ)
If FileLength(1) > 1
deltakerliste2 = ReadTable(1, {Adapter = "default"})
After updating to hurl 1.2 this will cause the program refer to the line with the readtable command and quit with the message: "Error deserializing item!"
When using hurl 1.1 the filesize will be below 1 and the readtable command will not be executed.

It might seem that with hurl 1.2 the Fail404 option is ignored in this case, and the file will get some unwanted content anyway.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Fail404 option with hurl 1.2

Post by amyren »

Realize my post probably should have been posted in the plugin section.

Anyway, here is a better example code to see what happens when you try to download from a URL that is not existing.

Code: Select all

@REQUIRE "hurl"
DownloadFile("https://google.com/nothing", {File = "test.txt", Fail404 = True, Adapter = "hurl"})
Using hurl 1.2, The code below will download a file test.txt, containing the 404 html code.
hurl 1.1 will not doenload anything, and instead give you the expected error code:
"Error in line 2 (dwn404.hws): File /nothing not found on this server!"
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Fail404 option with hurl 1.2

Post by airsoftsoftwair »

Right, looks like a bug, will be fixed.
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Fail404 option with hurl 1.2

Post by airsoftsoftwair »

Code: Select all

- Fix: The "Fail404" tag was ignored by hURL 
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Fail404 option with hurl 1.2

Post by amyren »

You did apply the fix almost a year ago, is there going to be a hurl update soon?
User avatar
airsoftsoftwair
Posts: 5433
Joined: Fri Feb 12, 2010 2:33 pm
Location: Germany
Contact:

Re: Fail404 option with hurl 1.2

Post by airsoftsoftwair »

Will take some more time because it will have some major changes like supporting openssl3.library on MorphOS as well as AmiSSL 5 on 68k/OS4 and AmiSSL 4 on AROS.
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Fail404 option with hurl 1.2

Post by amyren »

Thanks for explaining the situation.
While waiting for an update, what workaround could you recommend?
The easiest workaround is perhaps to revert to hurl1.1, but is there a way to get around it using 1.2?

Here is an example part of my code that suffers from this bug, the code returned will be 0 with hurl1.2 so it will continue and eventually quit without any error message when it starts processing the file

Code: Select all

		DownloadFile(file_url$, {File = myfile$, Fail404 = True, Adapter = "hurl"})
		code=GetLastError()
		If code<>0
			SystemRequest("File not found", "Cause: File does not exist,\nor network error","OK")
		Else		
			If Exists(myfile$)
					moai.DoMethod("lv2", "clear")
					OpenFile(1, myfile$, #MODE_READ)
							list2 = ReadTable(1, {Adapter = "default"})
							For i = 0 To ListItems(list2)-1
								var1$ = list2[i][0]
								var2$ = list2[i][1]
								var3$ = list2[i][2]
								moai.DoMethod("lv2", "insert", "bottom", var1$, var2$, var3$)
							Next
					CloseFile(1)
			EndIf	
Here is a MWE to show that the error code will be different using hurl1.2

Code: Select all

@REQUIRE "hurl"
ExitOnError(False)
DownloadFile("https://google.com/mytest.dat", {Fail404 = True, Adapter = "hurl"})
code=GetLastError()
SystemRequest("Display code", code,"OK")
WaitLeftMouse
User avatar
jPV
Posts: 603
Joined: Sat Mar 26, 2016 10:44 am
Location: RNO
Contact:

Re: Fail404 option with hurl 1.2

Post by jPV »

You shouldn't run your script with ExitOnError() disabled all the time, at least unless you have your own error function with RaiseOnError(). When you disable ExitOnError() you don't catch other fails as you experienced, which can lead to very random behaviour. So you should only disable the error handling for a single command or so.

Either use:

Code: Select all

		ExitOnError(False)
		DownloadFile(file_url$, {File = myfile$, Fail404 = True, Adapter = "hurl"})
		code=GetLastError()
		ExitOnError(True)
Or in a shorter way:

Code: Select all

		code = ?DownloadFile(file_url$, {File = myfile$, Fail404 = True, Adapter = "hurl"})
Then for a workaround you could check if ReadTable() fails, for example like this:

Code: Select all

code, list2 = ?ReadTable(1, {Adapter = "default"})
And not continuing on the For loop if that fails.

BTW. as a reminder, if you don't use these variables anywhere else, remember to declare them Local to avoid mess elsewhere, to save some memory, and to make the script faster :)
amyren
Posts: 352
Joined: Thu May 02, 2019 11:53 am

Re: Fail404 option with hurl 1.2

Post by amyren »

jPV wrote: Sat Mar 11, 2023 12:29 pm You shouldn't run your script with ExitOnError() disabled all the time, at least unless you have your own error function with RaiseOnError().
Or in a shorter way:

Code: Select all

		code = ?DownloadFile(file_url$, {File = myfile$, Fail404 = True, Adapter = "hurl"})
Thanks. That was a better way, omitting the ExitOnError thing althogether.
Then for a workaround you could check if ReadTable() fails, for example like this:

Code: Select all

code, list2 = ?ReadTable(1, {Adapter = "default"})
And not continuing on the For loop if that fails.
Thanks again, I have applied this now in my code.

I had another file that was just a textfile, so I could not use Readtable for it.
That I resolved like this to avoid to process the file in case it is a html file:

Code: Select all

OpenFile(1, premieringfil$)
	Local tmp$ = ReadString(1, 9)
CloseFile(1)
If tmp$ = "<!DOCTYPE"
...etc
Post Reply