reporting errors and warnings

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

reporting errors and warnings

adrianv
It appears that when writing my own functions, I have two ways of creating
error or warning messages.   I can use assert to make an error by writing:

dummy_variable = assert(condition, "Error message text"),

which sort of works.  It's annoying that I need the dummy variable.  And
it's also clutter that the condition gets displayed to the user.  But for
warning messages, it appears that the advice is to use echo() and make the
text yellow.  This seems ineffective because the statistics at the end of a
render always scroll off any text actually produced by the code, so I'm
reliant on that report at the top that tells me I had warnings so I know to
go look for them.    

It would be nice if there was a way to make real error and warning messages,
e.g. as a flag to the echo() command, or as a new command that could
generate errors and warnings.  Is there any plan to add this feature?  



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

tp3
On 16.03.19 16:13, adrianv wrote:
> It's annoying that I need the dummy variable.

Why would you need that?

   module fail() {
       assert(false, "meh");
       cube();
   }

   fail();

gives me a very nice

   ERROR: Assertion 'false': "meh" failed in file tp, line 2
   TRACE: called by 'assert', in file tp, line 2.
   TRACE: called by 'fail', in file tp, line 6.

ciao,
   Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

Ronaldo
In reply to this post by adrianv
It isn't ideal but we may get a warning count with something like:

xpto = condition ? echo( xpto, "your warning message") 0: 0

where xpto isn't used anywhere.

A sábado, 16/03/2019, 15:14, adrianv <[hidden email]> escreveu:
It appears that when writing my own functions, I have two ways of creating
error or warning messages.   I can use assert to make an error by writing:

dummy_variable = assert(condition, "Error message text"),

which sort of works.  It's annoying that I need the dummy variable.  And
it's also clutter that the condition gets displayed to the user.  But for
warning messages, it appears that the advice is to use echo() and make the
text yellow.  This seems ineffective because the statistics at the end of a
render always scroll off any text actually produced by the code, so I'm
reliant on that report at the top that tells me I had warnings so I know to
go look for them.   

It would be nice if there was a way to make real error and warning messages,
e.g. as a flag to the echo() command, or as a new command that could
generate errors and warnings.  Is there any plan to add this feature? 



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
In reply to this post by tp3
tp3 wrote

> On 16.03.19 16:13, adrianv wrote:
>> It's annoying that I need the dummy variable.
>
> Why would you need that?
>
>    module fail() {
>        assert(false, "meh");
>        cube();
>    }
>
>    fail();
>
> gives me a very nice
>
>    ERROR: Assertion 'false': "meh" failed in file tp, line 2
>    TRACE: called by 'assert', in file tp, line 2.
>    TRACE: called by 'fail', in file tp, line 6.

You don't get the message because you wrote a module instead of a function.
If I write a function:

function fail() = let(
    assert(true, "It failed"))
   0;

a=fail();
                 
then I get

Loaded design '/home/adrian/scad/a.scad'.
Compiling design (CSG Tree generation)...
WARNING: Assignment without variable name undef, in file a.scad, line 1
Compiling design (CSG Products generation)...
Geometries in cache: 1
Geometry cache size in bytes: 1360
CGAL Polyhedrons in cache: 0
CGAL cache size in bytes: 0
Compiling design (CSG Products normalization)...
Normalized CSG tree has 0 elements
Compile and preview finished.
Total rendering time: 0 hours, 0 minutes, 0 seconds

The warning appears even when the assert succeeds---I just always get that
warning.  So I need a dummy variable on every assert call.  I need them on
echo calls within function as well.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

tp3
> function fail() = let(
>      assert(true, "It failed"))
>     0;
>
> a=fail();
>                    
> WARNING: Assignment without variable name undef, in file a.scad, line 1

Yes, you get a warning because that code is assigning a
positional variable in let which is useless as there is
no way to access it afterwards.

I would use the function assert() like that:

   function f(i) = let(x = assert(i > 1, "It failed") i) x * x;

   echo(f1 = f(3));
   echo(f2 = f(-3));

ciao,
   Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
tp3 wrote

> Yes, you get a warning because that code is assigning a
> positional variable in let which is useless as there is
> no way to access it afterwards.
>
> I would use the function assert() like that:
>
>    function f(i) = let(x = assert(i > 1, "It failed") i) x * x;
>
>    echo(f1 = f(3));
>    echo(f2 = f(-3));

I understand the behavior.  But it's still annoying.  

I'm not sure I understand your suggestion.  It looks like you're suggesting
entangling the assert statement up with a nearby assignment.  I think from a
readability and maintainability perspective, this is worse than using dummy
variables.  

Code example:

function roundcorners(path, curve, type, all=undef,  closed=true) =
  let(
    default_curvature = 1,   // default curvature for "smooth" curves
    dummy1=assert(curve=="smooth" || curve=="circle", "Unknown curve type in
roundcorners"),
    typeok = type == "cut" || (curve=="circle" && type=="radius") ||
                                (curve=="smooth" && type=="joint"),
    dummy2=assert(typeok, curve=="circle" ? "In roundcorners 'circle' curve
requires 'type' of 'radius' or 'cut'":
                                     "In roundcorners 'smooth' curve
requires 'type' of 'joint' or 'cut'"),
    <many more lines of code follow>
   
Having to use the dummy variables is a nuisance but if I had to take my pick
I'd prefer a real warning/error generating command over a workaround for
this, which seems like it might be syntactically complex.  The best idea I
had for a workaround would be an official reusable dummy variable that
doesn't produce the "ignoring duplicate variable" warning, because the main
complication here is having to make sure all the dummy variables have unique
names.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

nophead
You don't need a dummy variable because assert can prefix an expression. E.g.

      let (nb = norm(binormal),   x = assert(nb > 0.00001, "first three points are colinear") nb))


On Sat, 16 Mar 2019 at 16:24, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, you get a warning because that code is assigning a
> positional variable in let which is useless as there is
> no way to access it afterwards.
>
> I would use the function assert() like that:
>
>    function f(i) = let(x = assert(i > 1, "It failed") i) x * x;
>
>    echo(f1 = f(3));
>    echo(f2 = f(-3));

I understand the behavior.  But it's still annoying. 

I'm not sure I understand your suggestion.  It looks like you're suggesting
entangling the assert statement up with a nearby assignment.  I think from a
readability and maintainability perspective, this is worse than using dummy
variables. 

Code example:

function roundcorners(path, curve, type, all=undef,  closed=true) =
  let(
    default_curvature = 1,   // default curvature for "smooth" curves
    dummy1=assert(curve=="smooth" || curve=="circle", "Unknown curve type in
roundcorners"),
    typeok = type == "cut" || (curve=="circle" && type=="radius") ||
                                (curve=="smooth" && type=="joint"),
    dummy2=assert(typeok, curve=="circle" ? "In roundcorners 'circle' curve
requires 'type' of 'radius' or 'cut'":
                                     "In roundcorners 'smooth' curve
requires 'type' of 'joint' or 'cut'"),
    <many more lines of code follow>

Having to use the dummy variables is a nuisance but if I had to take my pick
I'd prefer a real warning/error generating command over a workaround for
this, which seems like it might be syntactically complex.  The best idea I
had for a workaround would be an official reusable dummy variable that
doesn't produce the "ignoring duplicate variable" warning, because the main
complication here is having to make sure all the dummy variables have unique
names. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
tp3
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

tp3
Yes, like nophead wrote, you should not need that.

Here's a more detailed example:

   function f(a, b) =
     assert(a < 0, "wrong a") // assert input
     assert(b > 0, "wrong b") // assert input
     let (c = a + b) // derive a new value from input
     assert(c != 0, "wrong c") // assert derived value
     a * b; // calculate

   echo(f(-3, 5)); // ECHO: -15
   //echo(f(3, 6)); // ERROR: Assertion '(a < 0)': "wrong a" failed in file tp, line 3
   //echo(f(-4, -3)); // ERROR: Assertion '(b > 0)': "wrong b" failed in file tp, line 4
   //echo(f(-1, 1)); // ERROR: Assertion '(c != 0)': "wrong c" failed in file tp, line 6

ciao,
   Torsten.

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
-- Torsten
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
tp3 wrote

> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments.  

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

nophead
Perhaps assert should be changed to a warning and if you want it to stop like an error then you select stop on first warning.

On Sat, 16 Mar 2019 at 17:59, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments. 

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

lostapathy
Are there any other languages that use assert like you propose?  I can't think of any where assert doesn't bring things to a full stop.  I don't think OpenSCAD should be the first.





On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop like an error then you select stop on first warning.

On Sat, 16 Mar 2019 at 17:59, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments. 

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

nophead
Well I suppose the alternative is to add a warning statement and function, which duplicates all the same logic.

On Sat, 16 Mar 2019 at 19:15, Joe Francis <[hidden email]> wrote:
Are there any other languages that use assert like you propose?  I can't think of any where assert doesn't bring things to a full stop.  I don't think OpenSCAD should be the first.





On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop like an error then you select stop on first warning.

On Sat, 16 Mar 2019 at 17:59, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments. 

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

lostapathy
I think that makes a lot more sense.

If a library author needs a way to bail out if something is hopelessly wrong, that capability shouldn't get taken away because a user preference says "just treat asserts like warnings".  Even if that library author is just me from 6 months ago :). 

I do this all the time to verify the relationship between parameters.  If something won't work, I want it to fail immediately rather than spend a couple minutes rendering something that doesn't make any sense.

Putting together a warning() method like that should be doable in userspace, too.





On 3/16/19 2:17 PM, nop head wrote:
Well I suppose the alternative is to add a warning statement and function, which duplicates all the same logic.

On Sat, 16 Mar 2019 at 19:15, Joe Francis <[hidden email]> wrote:
Are there any other languages that use assert like you propose?  I can't think of any where assert doesn't bring things to a full stop.  I don't think OpenSCAD should be the first.





On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop like an error then you select stop on first warning.

On Sat, 16 Mar 2019 at 17:59, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments. 

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org


_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

nophead
You can echo warnings in user space but I don't think they will stop on first warning.

On Sat, 16 Mar 2019 at 19:27, Joe Francis <[hidden email]> wrote:
I think that makes a lot more sense.

If a library author needs a way to bail out if something is hopelessly wrong, that capability shouldn't get taken away because a user preference says "just treat asserts like warnings".  Even if that library author is just me from 6 months ago :). 

I do this all the time to verify the relationship between parameters.  If something won't work, I want it to fail immediately rather than spend a couple minutes rendering something that doesn't make any sense.

Putting together a warning() method like that should be doable in userspace, too.





On 3/16/19 2:17 PM, nop head wrote:
Well I suppose the alternative is to add a warning statement and function, which duplicates all the same logic.

On Sat, 16 Mar 2019 at 19:15, Joe Francis <[hidden email]> wrote:
Are there any other languages that use assert like you propose?  I can't think of any where assert doesn't bring things to a full stop.  I don't think OpenSCAD should be the first.





On 3/16/19 1:58 PM, nop head wrote:
Perhaps assert should be changed to a warning and if you want it to stop like an error then you select stop on first warning.

On Sat, 16 Mar 2019 at 17:59, adrianv <[hidden email]> wrote:
tp3 wrote
> Yes, like nophead wrote, you should not need that.
>
> Here's a more detailed example:
>
>    function f(a, b) =
>      assert(a < 0, "wrong a") // assert input
>      assert(b > 0, "wrong b") // assert input
>      let (c = a + b) // derive a new value from input
>      assert(c != 0, "wrong c") // assert derived value
>      a * b; // calculate

This is a great solution to the problem.  I don't like nophead's solution
because it mingles the computation into the assert in a way that's hard to
read, but this approach is clear.  It didn't occur to me that assert could
take children.  (This isn't mentioned in the manual at all.)   I do wish
that let would allow a dangling comma on the last expression, which would
make it easier to insert and delete assignments. 

But regarding the other issue, I still think it would be nice if there was a
way to generate warning and error messages from my code, without funny
business.  It would be more clear to a user to see

ERROR: Value 'a' must be larger than zero in file tp, line 3

than

ERROR: Assertion '(a>0)': "Value 'a' must be larger than zero" failed in
file tp, line 3.

And of course there's no mechanism at all to generate a warning. 




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
In reply to this post by nophead
nophead wrote
> Perhaps assert should be changed to a warning and if you want it to stop
> like an error then you select stop on first warning.

I don't think so.  Some situations just call for warnings.  And some are
errors.   The first warning isn't an error.  

I edited the manual to add the example of using assert in a function.  I'm
not sure I correctly stated how assert works, though, so someone might want
to check.   It looks like it returns the union of its children if you give
it children--is there any reason you'd ever want to do this?  But is using
it in an expression context different?  


> Well I suppose the alternative is to add a warning statement and function,
> which duplicates all the same logic.

I think it would be better to add an error statement that has a  flag for
severity and which doesn't include all the extra verbiage, so you could
write

error(c<=0,"Must set c>0");     // Displays:  ERROR: Must set c>0, in file
foo.scad, line 3
error(check_bounds(c),"c is close to zero",warning=true);  // Displays:
WARNING: c is close to zero, in file foo.scad, line 25

Note there is no word "failed" and no assertion condition displayed on
output, and no extra quote characters.  I have already found it necessary to
save condition results into variables so I don't put a long condition into
the assert because I don't want that complicated condition test to display
to the user.  


lostapathy wrote
> Putting together a warning() method like that should be doable in
> userspace,
> too.

You can't create warnings in userspace if there's no way to actually make a
real warning.  You can just make yellow text.  But it's not the same.  





--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

doug.moen
In the Curv language, I have 4 operations called 'print', 'assert', 'warning' and 'error', and none of them can be replaced by the others.

'print' is like 'echo' in OpenSCAD.

'assert(condition)' aborts the program if condition is false, printing an error message and a stack trace.

'error(message)' aborts the program, printing the message and a stack trace. Unlike 'assert', you can use error in either a statement context or an expression context. That is, you can write 'x < 0 ? error("negative x") : f(x)'.

'warning(message)' prints the message followed by a stack trace, and the program keeps running.

So, based on this experience, I think it is useful to have separate 'warning' and 'error' operations.

Doug Moen.

On Sat, Mar 16, 2019, at 3:38 PM, adrianv wrote:

> nophead wrote
> > Perhaps assert should be changed to a warning and if you want it to stop
> > like an error then you select stop on first warning.
>
> I don't think so.  Some situations just call for warnings.  And some are
> errors.   The first warning isn't an error.  
>
> I edited the manual to add the example of using assert in a function.  I'm
> not sure I correctly stated how assert works, though, so someone might want
> to check.   It looks like it returns the union of its children if you give
> it children--is there any reason you'd ever want to do this?  But is using
> it in an expression context different?  
>
>
> > Well I suppose the alternative is to add a warning statement and function,
> > which duplicates all the same logic.
>
> I think it would be better to add an error statement that has a  flag for
> severity and which doesn't include all the extra verbiage, so you could
> write
>
> error(c<=0,"Must set c>0");     // Displays:  ERROR: Must set c>0, in file
> foo.scad, line 3
> error(check_bounds(c),"c is close to zero",warning=true);  // Displays:
> WARNING: c is close to zero, in file foo.scad, line 25
>
> Note there is no word "failed" and no assertion condition displayed on
> output, and no extra quote characters.  I have already found it necessary to
> save condition results into variables so I don't put a long condition into
> the assert because I don't want that complicated condition test to display
> to the user.  
>
>
> lostapathy wrote
> > Putting together a warning() method like that should be doable in
> > userspace,
> > too.
>
> You can't create warnings in userspace if there's no way to actually make a
> real warning.  You can just make yellow text.  But it's not the same.  
>
>
>
>
>
> --
> Sent from: http://forum.openscad.org/
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

RevarBat
Having just written functions and modules to emulate error() and warning(), that only really output colored text, I agree that there should be builtins that stop compilation or trigger the warnings popup.

 - Revar


> On Mar 16, 2019, at 1:54 PM, Doug Moen <[hidden email]> wrote:
>
> In the Curv language, I have 4 operations called 'print', 'assert', 'warning' and 'error', and none of them can be replaced by the others.
>
> 'print' is like 'echo' in OpenSCAD.
>
> 'assert(condition)' aborts the program if condition is false, printing an error message and a stack trace.
>
> 'error(message)' aborts the program, printing the message and a stack trace. Unlike 'assert', you can use error in either a statement context or an expression context. That is, you can write 'x < 0 ? error("negative x") : f(x)'.
>
> 'warning(message)' prints the message followed by a stack trace, and the program keeps running.
>
> So, based on this experience, I think it is useful to have separate 'warning' and 'error' operations.
>
> Doug Moen.
>
>> On Sat, Mar 16, 2019, at 3:38 PM, adrianv wrote:
>> nophead wrote
>>> Perhaps assert should be changed to a warning and if you want it to stop
>>> like an error then you select stop on first warning.
>>
>> I don't think so.  Some situations just call for warnings.  And some are
>> errors.   The first warning isn't an error.  
>>
>> I edited the manual to add the example of using assert in a function.  I'm
>> not sure I correctly stated how assert works, though, so someone might want
>> to check.   It looks like it returns the union of its children if you give
>> it children--is there any reason you'd ever want to do this?  But is using
>> it in an expression context different?  
>>
>>
>>> Well I suppose the alternative is to add a warning statement and function,
>>> which duplicates all the same logic.
>>
>> I think it would be better to add an error statement that has a  flag for
>> severity and which doesn't include all the extra verbiage, so you could
>> write
>>
>> error(c<=0,"Must set c>0");     // Displays:  ERROR: Must set c>0, in file
>> foo.scad, line 3
>> error(check_bounds(c),"c is close to zero",warning=true);  // Displays:
>> WARNING: c is close to zero, in file foo.scad, line 25
>>
>> Note there is no word "failed" and no assertion condition displayed on
>> output, and no extra quote characters.  I have already found it necessary to
>> save condition results into variables so I don't put a long condition into
>> the assert because I don't want that complicated condition test to display
>> to the user.  
>>
>>
>> lostapathy wrote
>>> Putting together a warning() method like that should be doable in
>>> userspace,
>>> too.
>>
>> You can't create warnings in userspace if there's no way to actually make a
>> real warning.  You can just make yellow text.  But it's not the same.  
>>
>>
>>
>>
>>
>> --
>> Sent from: http://forum.openscad.org/
>>
>> _______________________________________________
>> OpenSCAD mailing list
>> [hidden email]
>> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
>>
>
> _______________________________________________
> OpenSCAD mailing list
> [hidden email]
> http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
How would I write a modular code that checks for an error condition and
prints a message that I can use without dummy variables?  Is this possible?
Could it be possible with a new error() function?  

function do_something(x,y,mode) =
    check_valid(mode,"mode", ["fast","slow","big","tall","purple"])
    <function calculation>;

where check_valid checks() checks whether mode is on the list and if it's
not constructs a message like "Input 'mode' was set to <garbage>; it must be
one of 'fast', 'slow', 'big', 'tall', 'purple'") and calls assert() or
error().  

I would rather avoid having to write a custom assert every time where I have
to repeat the list of options.  But if I write a function, then it needs to
be part of an assignment, so then I need the dummy variable.  Is there a way
around this?  



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

nophead
function do_something(x,y,mode) = 
    assert(check_valid(mode,"mode", ["fast","slow","big","tall","purple"]), "bad mode")
    <function calculation>;

On Mon, 25 Mar 2019 at 13:13, adrianv <[hidden email]> wrote:
How would I write a modular code that checks for an error condition and
prints a message that I can use without dummy variables?  Is this possible?
Could it be possible with a new error() function? 

function do_something(x,y,mode) =
    check_valid(mode,"mode", ["fast","slow","big","tall","purple"])
    <function calculation>;

where check_valid checks() checks whether mode is on the list and if it's
not constructs a message like "Input 'mode' was set to <garbage>; it must be
one of 'fast', 'slow', 'big', 'tall', 'purple'") and calls assert() or
error(). 

I would rather avoid having to write a custom assert every time where I have
to repeat the list of options.  But if I write a function, then it needs to
be part of an assignment, so then I need the dummy variable.  Is there a way
around this? 



--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
Reply | Threaded
Open this post in threaded view
|

Re: reporting errors and warnings

adrianv
nophead wrote
> function do_something(x,y,mode) =
>     assert(check_valid(mode,"mode",
> ["fast","slow","big","tall","purple"]),
> "bad mode")
>    
> <function calculation>
> ;

My initial reaction was that this doesn't solve the problem, since the
actual error message text says "bad mode" instead of actually giving the
informative content.  But in fact it might actually be *better* than the
status quo if the check_valid function displays its error in red text so it
looks like part of the error message.  I'd call it a hack, but a decent one.  




--
Sent from: http://forum.openscad.org/

_______________________________________________
OpenSCAD mailing list
[hidden email]
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org
12