2019-03-23 04:13:18 +00:00
|
|
|
//////////////////////////////////////////////////////////////////////
|
2019-05-16 04:07:27 +00:00
|
|
|
// LibFile: errors.scad
|
|
|
|
// Functions and modules to facilitate error reporting.
|
2019-03-23 04:13:18 +00:00
|
|
|
// To use, include this line at the top of your file:
|
|
|
|
// ```
|
2019-04-22 08:08:41 +00:00
|
|
|
// use <BOSL2/std.scad>
|
2019-03-23 04:13:18 +00:00
|
|
|
// ```
|
|
|
|
//////////////////////////////////////////////////////////////////////
|
|
|
|
|
|
|
|
|
|
|
|
|
2019-05-16 04:07:27 +00:00
|
|
|
// Section: Warnings and Errors
|
2019-03-23 04:13:18 +00:00
|
|
|
|
|
|
|
|
2019-10-31 02:52:53 +00:00
|
|
|
// Module: no_children()
|
|
|
|
// Usage:
|
|
|
|
// no_children($children);
|
|
|
|
// Description:
|
|
|
|
// Assert that the calling module does not support children. Prints an error message to this effect and fails if children are present,
|
|
|
|
// as indicated by its argument.
|
|
|
|
// Arguments:
|
|
|
|
// $children = number of children the module has.
|
|
|
|
module no_children(count) {
|
|
|
|
assert(count==0, str("Module ",parent_module(1),"() does not support child modules"));
|
|
|
|
}
|
|
|
|
|
|
|
|
|
2019-05-14 22:23:13 +00:00
|
|
|
// Function&Module: echo_error()
|
2019-03-23 04:13:18 +00:00
|
|
|
// Usage:
|
|
|
|
// echo_error(msg, [pfx]);
|
2019-03-27 09:33:52 +00:00
|
|
|
// Description:
|
|
|
|
// Emulates printing of an error message. The text will be shaded red.
|
|
|
|
// You can also use this as a function call from a function.
|
2019-03-23 04:13:18 +00:00
|
|
|
// Arguments:
|
|
|
|
// msg = The message to print.
|
|
|
|
// pfx = The prefix to print before `msg`. Default: `ERROR`
|
|
|
|
module echo_error(msg, pfx="ERROR") {
|
2020-05-30 02:04:34 +00:00
|
|
|
echo(str("<p style=\"background-color: #ffb0b0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
2019-03-23 04:13:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 08:40:53 +00:00
|
|
|
function echo_error(msg, pfx="ERROR") =
|
2020-05-30 02:04:34 +00:00
|
|
|
echo(str("<p style=\"background-color: #ffb0b0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
2019-03-25 08:40:53 +00:00
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-14 22:23:13 +00:00
|
|
|
// Function&Module: echo_warning()
|
2019-03-23 04:13:18 +00:00
|
|
|
// Usage:
|
|
|
|
// echo_warning(msg, [pfx]);
|
2019-03-27 09:33:52 +00:00
|
|
|
// Description:
|
|
|
|
// Emulates printing of a warning message. The text will be shaded yellow.
|
|
|
|
// You can also use this as a function call from a function.
|
2019-03-23 04:13:18 +00:00
|
|
|
// Arguments:
|
|
|
|
// msg = The message to print.
|
|
|
|
// pfx = The prefix to print before `msg`. Default: `WARNING`
|
|
|
|
module echo_warning(msg, pfx="WARNING") {
|
2020-05-30 02:04:34 +00:00
|
|
|
echo(str("<p style=\"background-color: #ffffb0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
2019-03-23 04:13:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 08:40:53 +00:00
|
|
|
function echo_warning(msg, pfx="WARNING") =
|
2020-05-30 02:04:34 +00:00
|
|
|
echo(str("<p style=\"background-color: #ffffb0\"><b>", pfx, ":</b> ", msg, "</p>"));
|
2019-03-25 08:40:53 +00:00
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-14 22:23:13 +00:00
|
|
|
// Function&Module: deprecate()
|
2019-03-23 04:13:18 +00:00
|
|
|
// Usage:
|
|
|
|
// deprecate(name, [suggest]);
|
2019-03-27 09:33:52 +00:00
|
|
|
// Description:
|
|
|
|
// Show module deprecation warnings.
|
|
|
|
// You can also use this as a function call from a function.
|
2019-03-23 04:13:18 +00:00
|
|
|
// Arguments:
|
|
|
|
// name = The name of the module that is deprecated.
|
|
|
|
// suggest = If given, the module to recommend using instead.
|
|
|
|
module deprecate(name, suggest=undef) {
|
2020-05-30 02:04:34 +00:00
|
|
|
echo_warning(pfx="DEPRECATED",
|
|
|
|
str(
|
|
|
|
"`<code>", name, "</code>` is deprecated and should not be used.",
|
|
|
|
is_undef(suggest)? "" : str(
|
|
|
|
" You should use `<code>", suggest, "</code>` instead."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2019-03-23 04:13:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 08:40:53 +00:00
|
|
|
function deprecate(name, suggest=undef) =
|
2020-05-30 02:04:34 +00:00
|
|
|
echo_warning(pfx="DEPRECATED",
|
|
|
|
str(
|
|
|
|
"`<code>", name, "</code>` is deprecated and should not be used.",
|
|
|
|
is_undef(suggest)? "" : str(
|
|
|
|
" You should use `<code>", suggest, "</code>` instead."
|
|
|
|
)
|
|
|
|
)
|
|
|
|
);
|
2019-03-25 08:40:53 +00:00
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
|
2019-05-14 22:23:13 +00:00
|
|
|
// Function&Module: deprecate_argument()
|
2019-03-23 04:13:18 +00:00
|
|
|
// Usage:
|
|
|
|
// deprecate(name, arg, [suggest]);
|
2019-03-27 09:33:52 +00:00
|
|
|
// Description:
|
|
|
|
// Show argument deprecation warnings.
|
|
|
|
// You can also use this as a function call from a function.
|
2019-03-23 04:13:18 +00:00
|
|
|
// Arguments:
|
2019-03-27 09:33:52 +00:00
|
|
|
// name = The name of the module/function the deprecated argument is used in.
|
2019-03-23 04:13:18 +00:00
|
|
|
// arg = The name of the deprecated argument.
|
|
|
|
// suggest = If given, the argument to recommend using instead.
|
|
|
|
module deprecate_argument(name, arg, suggest=undef) {
|
2020-05-30 02:04:34 +00:00
|
|
|
echo_warning(pfx="DEPRECATED ARG", str(
|
|
|
|
"In `<code>", name, "</code>`, ",
|
|
|
|
"the argument `<code>", arg, "</code>` ",
|
|
|
|
"is deprecated and should not be used.",
|
|
|
|
is_undef(suggest)? "" : str(
|
|
|
|
" You should use `<code>", suggest, "</code>` instead."
|
|
|
|
)
|
|
|
|
));
|
2019-03-23 04:13:18 +00:00
|
|
|
}
|
|
|
|
|
2019-03-25 08:40:53 +00:00
|
|
|
function deprecate_argument(name, arg, suggest=undef) =
|
2020-05-30 02:04:34 +00:00
|
|
|
echo_warning(pfx="DEPRECATED ARG", str(
|
|
|
|
"In `<code>", name, "</code>`, ",
|
|
|
|
"the argument `<code>", arg, "</code>` ",
|
|
|
|
"is deprecated and should not be used.",
|
|
|
|
is_undef(suggest)? "" : str(
|
|
|
|
" You should use `<code>", suggest, "</code>` instead."
|
|
|
|
)
|
|
|
|
));
|
2019-03-25 08:40:53 +00:00
|
|
|
|
2019-03-23 04:13:18 +00:00
|
|
|
|
|
|
|
|
2020-05-30 02:04:34 +00:00
|
|
|
// vim: expandtab tabstop=4 shiftwidth=4 softtabstop=4 nowrap
|