action #176475
closedcoordination #154768: [saga][epic][ux] State-of-art user experience for openQA
coordination #176487: [epic] Up-to-date Perl stack
Use Feature::Compat::Try in our code - os-autoinst size:S
Description
Motivation¶
Using modern builtin perl features
https://metacpan.org/pod/Feature::Compat::Try is a module that provides the same
interface and functionality as the new try
feature for older perl versions (<
5.34.0).
It automaticallly uses the builtin try
feature for perl >= 5.34.0
use Feature::Compat::Try;
# In perl 5.34.0 same as:
use experimental 'try';
# Leap 16 will have perl 5.38, so as soon as we can make
# perl 5.38 the minimum version, we would write:
use v5.36; # strict, warnings, signatures, ...
use experimental 'try';
# With perl 5.40 it would be just:
use v5.40; # strict, warnings, signatures, try, ...
The basic try/catch
feature got non-experimental with 5.40, so it's safe to
use.
The finally
part is still experimental, so theoretically implementation
changes could happen.
The feature is tracked here: https://github.com/Perl/perl5/issues/18760
Example Feature::Compat::Try vs. eval and Try::Tiny¶
Feature::Compat::Try¶
use v5.12;
use warnings;
use experimental 'signatures';
use Feature::Compat::Try;
sub foo ($fail) {
try {
say "trying";
die "oops" if $fail;
return "pass"; # returns from foo()
}
catch ($e) {
warn "Exception: $e";
return "fail"; # returns from foo()
}
finally {
say "whatever happens, I'm here";
}
say "end of subroutine"; # not reached
}
say foo(0);
say foo(1);
Try::Tiny¶
use v5.12;
use warnings;
use experimental 'signatures';
use Try::Tiny;
sub foo ($fail) {
my $res;
try {
say "trying";
die "oops" if $fail;
$res = "pass";
return "pass"; # does not return from foo()
}
catch {
warn "Exception: $_";
$res = "fail";
return "fail"; # does not return from foo()
}
finally {
say "whatever happens, I'm here";
};
return $res;
}
say foo(0);
say foo(1);
Pro¶
- In Leap >= 15.5
Compared to Try::Tiny:
- Future builtin
- Can return from subroutine
catch ($some_name)
instead of$_
- Real block syntax element
{}
- no;
at the end needed
Con¶
- Still partially experimental in 5.40
Updated by tinita about 1 month ago
- Related to action #133112: Switch unit tests to Test2-Suite added
Updated by okurz about 1 month ago
- Assignee set to tinita
- Target version set to Ready
As clarified with tinita she will check on the status of the finally part with someone from perl5porters and depending on the outcome we continue or leave more for later.
Updated by tinita about 1 month ago ยท Edited
- Description updated (diff)
- Target version changed from Ready to future
So unfortunately finally
seems to be still experimental. The issue is tracked here: https://github.com/Perl/perl5/issues/18760
It seems it's kind of the same implementation as for the defer
feature, see https://metacpan.org/pod/Feature::Compat::Defer . (Which is also something that I would like to use in the future. For now we have Mojo:Util's scope_guard
)
Updated by tinita about 1 month ago
Note that Try::Tiny provides finally
as well, but we don't use it anywhere in our code, so we could switch to the try
feature anyway right now.
Updated by okurz about 1 month ago
- Status changed from New to In Progress
- Assignee changed from tinita to okurz
- Target version changed from future to Ready
Updated by okurz about 1 month ago
- Blocks action #176319: testapi power function call "off" needs to be handled gracefully by os-autoinst size:S added
Updated by openqa_review about 1 month ago
- Due date set to 2025-02-24
Setting due date based on mean cycle time of SUSE QE Tools
Updated by okurz about 1 month ago
https://github.com/os-autoinst/openQA/pull/6166 is how the corresponding code change would look like for openQA. I did not find relevant uses of Try::Tiny (or Test::Fatal) in related projects like openSUSE/qem-dashboard or os-autoinst-common, etc.
Updated by okurz about 1 month ago
- Copied to action #176862: [beginner][easy] Use Feature::Compat::Try in our code - openQA size:S added
Updated by okurz about 1 month ago
- Subject changed from Use Feature::Compat::Try in our code to Use Feature::Compat::Try in our code - os-autoinst
Updated by okurz about 1 month ago
2 PRs merged. Triggered https://app.circleci.com/pipelines/github/os-autoinst/openQA/15677/workflows/22743343-c15d-4a34-9075-39f2ebe49e39 which might bring us the updated dependency in openQA already otherwise we would need to wait until tomorrow
Updated by okurz about 1 month ago
- Status changed from In Progress to Feedback
Waiting for https://build.opensuse.org/package/show/devel:openQA/os-autoinst_dev to be built
Updated by okurz about 1 month ago
https://github.com/os-autoinst/os-autoinst/pull/2652 merged. I would like to let the new dependency go through the whole pipelines. Then we can follow up with the rest.
Updated by okurz about 1 month ago
Updated by okurz about 1 month ago
No bad effect from https://github.com/os-autoinst/os-autoinst/pull/2650 observed yet. Preparing some related improvement that I found while working on the code, e.g. using more Mojo::File.
Updated by okurz 28 days ago
- Due date deleted (
2025-02-24) - Status changed from Feedback to Resolved
https://github.com/os-autoinst/os-autoinst/pull/2663 merged. Deployed and also no bad feedback about that.