1
1
Fork
You've already forked CodeUnit
0

Add ability to sink Errors #1

Closed
opened 2025年10月23日 00:02:24 +02:00 by librasteve · 2 comments
librasteve commented 2025年10月23日 00:02:24 +02:00 (Migrated from github.com)
Copy link

In raku App::Crag ver<0.0.35>, I have placed this line at the start of the MAIN to suppress all the stack trace info when an error occurs...

# Redirect STDERR to /dev/null
$*ERR = '/dev/null'.IO.open(:w);

However, this has met with limited success. It works on runtime errors such as 1/0, but not compile times errors.

Desired outcome:

~> crag
> 1/0
Error: X::Numeric::DivideByZero «Attempt to divide 1 by zero when coercing Rational to Str»
> 

I have tried the same idea inside the $cu.eval here but that does not work.

Actual outcome:

~> crag
> +$x
Use of uninitialized value $x of type Any in numeric context
 in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/resources/B4EA5A01DC96A0C8418F5A4882EDDFEB68838FE7 line 1
 in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/xx/B4EA5A01DC96A0C8418F5A4882EDDFEB68838FE7 line 1
 in sub MAIN at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/bin/crag.raku line 2
 in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/bin/crag.raku line 1
>

So, my request is for some kind of has $.stderr-to-devnull = False; attr on CodeUnit that I can override that dumps STDERR to dev/null please.

In raku App::Crag `ver<0.0.35>`, I have placed this line at the start of the MAIN to suppress all the stack trace info when an error occurs... ``` # Redirect STDERR to /dev/null $*ERR = '/dev/null'.IO.open(:w); ``` However, this has met with limited success. It works on runtime errors such as 1/0, but not compile times errors. Desired outcome: ``` ~> crag > 1/0 Error: X::Numeric::DivideByZero «Attempt to divide 1 by zero when coercing Rational to Str» > ``` I have tried the same idea inside the $cu.eval [here](https://github.com/librasteve/raku-App-Crag/blob/73f895d99824145a73a16bc8bbeb77bcc23e4ab7/lib/App/Crag.rakumod#L64) but that does not work. Actual outcome: ``` ~> crag > +$x Use of uninitialized value $x of type Any in numeric context in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/resources/B4EA5A01DC96A0C8418F5A4882EDDFEB68838FE7 line 1 in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/xx/B4EA5A01DC96A0C8418F5A4882EDDFEB68838FE7 line 1 in sub MAIN at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/bin/crag.raku line 2 in block <unit> at /Users/xx/.rakubrew/versions/moar-2025.08/share/perl6/site/bin/crag.raku line 1 > ``` So, my request is for some kind of `has $.stderr-to-devnull = False;` attr on CodeUnit that I can override that dumps STDERR to dev/null please.
lizmat commented 2025年12月16日 20:13:22 +01:00 (Migrated from github.com)
Copy link

I think that the latest version of CodeUnit solves this issue, and actually provides some more possibilities regarding handling of warnings.

So closing this issue now.

I think that the latest version of [CodeUnit](https://raku.land/zef:lizmat/CodeUnit) solves this issue, *and* actually provides some more possibilities regarding handling of warnings. So closing this issue now.
lizmat commented 2025年12月16日 21:37:58 +01:00 (Migrated from github.com)
Copy link

Sorry, this issue fell through the cracks.

The main issue was that warnings were caught and consequently shown on STDOUT rather than on STDERR.

I've just uploaded a new version of CodeUnit that:

  • correctly shows warning on STDERR by default
  • adds a :keep-warnings attribute / flag

The latter will store any warnings as CX::Warn objects in a new "warnings" attribute. The C method will return these as a List and reset them. So after running an expression in App::Crag, you are now able to see what the warnings were (if any) and take appropriate action.

Sorry, this issue fell through the cracks. The main issue was that warnings were caught and consequently shown on `STDOUT` rather than on `STDERR`. I've just uploaded a new version of `CodeUnit` that: - correctly shows warning on STDERR by default - adds a `:keep-warnings` attribute / flag The latter will store any warnings as `CX::Warn` objects in a new "warnings" attribute. The C<warnings> method will return these as a `List` and reset them. So after running an expression in `App::Crag`, you are now able to see what the warnings were (if any) and take appropriate action.
Sign in to join this conversation.
No Branch/Tag specified
main
0.0.10
0.0.9
0.0.8
0.0.7
0.0.6
0.0.5
0.0.4
0.0.3
0.0.2
0.0.1
Milestone
Clear milestone
No items
No milestone
Projects
Clear projects
No items
No project
Assignees
Clear assignees
No assignees
1 participant
Notifications
Due date
The due date is invalid or out of range. Please use the format "yyyy-mm-dd".

No due date set.

Dependencies

No dependencies set.

Reference
lizmat/CodeUnit#1
Reference in a new issue
lizmat/CodeUnit
No description provided.
Delete branch "%!s()"

Deleting a branch is permanent. Although the deleted branch may continue to exist for a short time before it actually gets removed, it CANNOT be undone in most cases. Continue?