discuss@lists.openscad.org

OpenSCAD general discussion Mailing-list

View all threads

reporting errors and warnings

A
adrianv
Sat, Mar 16, 2019 3:13 PM

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/

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/
TP
Torsten Paul
Sat, Mar 16, 2019 3:19 PM

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.

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.
RP
Ronaldo Persiano
Sat, Mar 16, 2019 3:27 PM

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 avm4@cornell.edu 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <avm4@cornell.edu> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
A
adrianv
Sat, Mar 16, 2019 4:00 PM

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/

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/
TP
Torsten Paul
Sat, Mar 16, 2019 4:08 PM

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.

> 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.
A
adrianv
Sat, Mar 16, 2019 4:23 PM

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/

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/
NH
nop head
Sat, Mar 16, 2019 4:29 PM

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 avm4@cornell.edu 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <avm4@cornell.edu> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >
TP
Torsten Paul
Sat, Mar 16, 2019 5:06 PM

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.

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.
A
adrianv
Sat, Mar 16, 2019 5:59 PM

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/

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/
NH
nop head
Sat, Mar 16, 2019 6:58 PM

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 avm4@cornell.edu 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
Discuss@lists.openscad.org
http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org

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 <avm4@cornell.edu> 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 > Discuss@lists.openscad.org > http://lists.openscad.org/mailman/listinfo/discuss_lists.openscad.org >