Macro errors are ignored in many cases

classic Classic list List threaded Threaded
3 messages Options
Reply | Threaded
Open this post in threaded view
|

Macro errors are ignored in many cases

Stein Rørvik
The release notes of 1.52j says
"errors in macro run() statements are now reported using a "Macro Error" dialog that displays the line number."

While useful in itself, it seems that this fix has introduced other problems.
Many errors now do not stop the macro running but lets it continue with unexpected results.

In the demo macro below, only case 5 works as it should.
The difference between case 4 and case 5 is that the latter has no parameters, and may give a hint to where the problem is.
Case 2 is especially dangerous. Case 3 is perhaps not really an error, just an inconvenience.

The errors in the demo macro aborts correctly in 1.52i so it is the above change in error handling that has caused the problem.

Demo macro:
------------------------------

//case 1
run("Blobs (25K)");
run("Clear", "slice");
//the command is invalid due to no selection, but the macro proceeds as if nothing happened

//case 2
run("T1 Head (2.4M, 16-bits)");
saveAs("GIF", getDirectory("temp") + "T1-Head.gif");
//command is invalid since 16-bit images cannot be saved as GIF
//throws no error, instead just produces an empty file and proceeds macro execution

//case 3
run("T1 Head (2.4M, 16-bits)");
run("Gif...");
//command is invalid since 16-bit images cannot be saved as GIF
//asks for filename; an empty file is generated
//then the interpreter throws an error and aborts macro
//the error should perhaps have appeared before asking for filename

//case 4
run("Close All");
run("Scale...", "x=0.5 y=0.5");
//command is invalid because no images are open
//the macro is aborted silently with no error

//case 5
run("Close All");
run("Scale...");
//command is invalid because no images are open
//the macro is aborted properly with an error

------------------------------


I am using daily build ImageJ 1.52k with Java 1.6 on Windows 7/64-bit.


Stein


--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro errors are ignored in many cases

Wayne Rasband-2
> On Jan 22, 2019, at 5:01 AM, Stein Rørvik <[hidden email]> wrote:
>
> The release notes of 1.52j says
> "errors in macro run() statements are now reported using a "Macro Error" dialog that displays the line number."
>
> While useful in itself, it seems that this fix has introduced other problems.
> Many errors now do not stop the macro running but lets it continue with unexpected results.

These regressions are fixed in the latest daily build (1.52k63).

-wayne

> In the demo macro below, only case 5 works as it should.
> The difference between case 4 and case 5 is that the latter has no parameters, and may give a hint to where the problem is.
> Case 2 is especially dangerous. Case 3 is perhaps not really an error, just an inconvenience.
>
> The errors in the demo macro aborts correctly in 1.52i so it is the above change in error handling that has caused the problem.
>
> Demo macro:
> ------------------------------
>
> //case 1
> run("Blobs (25K)");
> run("Clear", "slice");
> //the command is invalid due to no selection, but the macro proceeds as if nothing happened
>
> //case 2
> run("T1 Head (2.4M, 16-bits)");
> saveAs("GIF", getDirectory("temp") + "T1-Head.gif");
> //command is invalid since 16-bit images cannot be saved as GIF
> //throws no error, instead just produces an empty file and proceeds macro execution
>
> //case 3
> run("T1 Head (2.4M, 16-bits)");
> run("Gif...");
> //command is invalid since 16-bit images cannot be saved as GIF
> //asks for filename; an empty file is generated
> //then the interpreter throws an error and aborts macro
> //the error should perhaps have appeared before asking for filename
>
> //case 4
> run("Close All");
> run("Scale...", "x=0.5 y=0.5");
> //command is invalid because no images are open
> //the macro is aborted silently with no error
>
> //case 5
> run("Close All");
> run("Scale...");
> //command is invalid because no images are open
> //the macro is aborted properly with an error
>
> ------------------------------
>
>
> I am using daily build ImageJ 1.52k with Java 1.6 on Windows 7/64-bit.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html
Reply | Threaded
Open this post in threaded view
|

Re: Macro errors are ignored in many cases

Stein Rørvik
Thanks, this works as expected!

There is also another flaw in the macro error handling:

If a macro command other than run(... expects an image which is missing, the macro aborts but no line number nor name of the problematic command is given. This can be hard to debug. Commands expecting a selection which is missing shows the proper error message.

See this example. It just says "No image" instead of Macro error in Line 3.
The getSelectionCoordinates throws a full informational "Macro Error" message.

run("Close All");
print("bitDepth: ");
bd = bitDepth();
//fails because there is no image
print(bd);

run("Blobs (25K)");
getSelectionCoordinates(xpoints, ypoints);
//fails because there is no selection

Stein

-----Original Message-----
From: ImageJ Interest Group <[hidden email]> On Behalf Of Wayne Rasband
Sent: 22. januar 2019 17:42
To: [hidden email]
Subject: Re: Macro errors are ignored in many cases

> On Jan 22, 2019, at 5:01 AM, Stein Rørvik <[hidden email]> wrote:
>
> The release notes of 1.52j says
> "errors in macro run() statements are now reported using a "Macro Error" dialog that displays the line number."
>
> While useful in itself, it seems that this fix has introduced other problems.
> Many errors now do not stop the macro running but lets it continue with unexpected results.

These regressions are fixed in the latest daily build (1.52k63).

-wayne

> In the demo macro below, only case 5 works as it should.
> The difference between case 4 and case 5 is that the latter has no parameters, and may give a hint to where the problem is.
> Case 2 is especially dangerous. Case 3 is perhaps not really an error, just an inconvenience.
>
> The errors in the demo macro aborts correctly in 1.52i so it is the above change in error handling that has caused the problem.
>
> Demo macro:
> ------------------------------
>
> //case 1
> run("Blobs (25K)");
> run("Clear", "slice");
> //the command is invalid due to no selection, but the macro proceeds
> as if nothing happened
>
> //case 2
> run("T1 Head (2.4M, 16-bits)");
> saveAs("GIF", getDirectory("temp") + "T1-Head.gif"); //command is
> invalid since 16-bit images cannot be saved as GIF //throws no error,
> instead just produces an empty file and proceeds macro execution
>
> //case 3
> run("T1 Head (2.4M, 16-bits)");
> run("Gif...");
> //command is invalid since 16-bit images cannot be saved as GIF //asks
> for filename; an empty file is generated //then the interpreter throws
> an error and aborts macro //the error should perhaps have appeared
> before asking for filename
>
> //case 4
> run("Close All");
> run("Scale...", "x=0.5 y=0.5");
> //command is invalid because no images are open //the macro is aborted
> silently with no error
>
> //case 5
> run("Close All");
> run("Scale...");
> //command is invalid because no images are open //the macro is aborted
> properly with an error
>
> ------------------------------
>
>
> I am using daily build ImageJ 1.52k with Java 1.6 on Windows 7/64-bit.

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html

--
ImageJ mailing list: http://imagej.nih.gov/ij/list.html