-
Notifications
You must be signed in to change notification settings - Fork 205
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Return error when error happens in caching assets #2960
Conversation
@@ -296,6 +296,7 @@ sub engine_workit { | |||
my $assetkeys = detect_asset_keys(\%vars); | |||
if (my $cache_dir = $global_settings->{CACHEDIRECTORY}) { | |||
$shared_cache = do_asset_caching($job, \%vars, $cache_dir, $assetkeys, $webui_host, $pooldir); | |||
return $shared_cache if (ref($shared_cache) eq 'HASH' && $shared_cache->{error}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Maybe you don't even need to check for ref($shared_cache) eq 'HASH'
but just rely on the second condition
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Seems like do_asset_caching
can return undef
. To me it is not clear whether this is actually an error or not as well. Maybe it makes sense to adjust do_asset_caching
to always return a meaningful error message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
@Martchus sometimes it returns a dir
. Do you mean we could return a hash like this {error => , shared_dir => }
in do_asset_caching
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
That would at least be more readable. But so far the do_asset_caching
function might exit without an explicit return
statement. It would be better to have an explicit return
in all code paths to make it clear in any case what the function returns.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If I do not miss something, the do_asset_caching
will return 3 types of values: return undef
, return $shared_dir (string)
, return {error => $error_message}
. when it return {error => }
we need to stop the test and return error. Although checking the perl data type is not a good idea, I have no idea how to check the value to make it more simply.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
well, you can streamline this by replacing return undef
into return {error => $another_error_message}
and then use
return $shared_cache->{error} if $shared_cache->{error};
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Do you mean using return {error => $another_error_message}
to replace return undef
at the end of function do_asset_caching
? But there is still a situation that do_asset_caching
return a string. So the if $shared_cache->{error}
will report a error message that I mentioned in above message.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
BTW return undef
should be treated as success.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
If return undef
should be treated as success you can't implemant the suggestion by @okurz exactly but you can still follow the idea. In my opinion it is also better to return a consistent type and then only check for the presence of the error key to determine whether an error occurred. In the good case with no additional information you could return an empty hash.
Codecov Report
@@ Coverage Diff @@
## master #2960 +/- ##
==========================================
- Coverage 93.43% 93.40% -0.03%
==========================================
Files 190 190
Lines 11967 11969 +2
==========================================
- Hits 11181 11180 -1
- Misses 786 789 +3
Continue to review full report at Codecov.
|
@@ -296,6 +297,7 @@ sub engine_workit { | |||
my $assetkeys = detect_asset_keys(\%vars); | |||
if (my $cache_dir = $global_settings->{CACHEDIRECTORY}) { | |||
$shared_cache = do_asset_caching($job, \%vars, $cache_dir, $assetkeys, $webui_host, $pooldir); | |||
return $shared_cache if (ref($shared_cache) eq 'HASH'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
seems from my original proposal you turned this around. Can you now check for a correct value rather than check the ref type? I don't think checking perl types is a good style here.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, we might not have a better choice here as we can't check something like if $shared_cache->{error}
if $shared_cache
is actually a string. I think the current way as you provided is fine
@@ -296,6 +297,7 @@ sub engine_workit { | |||
my $assetkeys = detect_asset_keys(\%vars); | |||
if (my $cache_dir = $global_settings->{CACHEDIRECTORY}) { | |||
$shared_cache = do_asset_caching($job, \%vars, $cache_dir, $assetkeys, $webui_host, $pooldir); | |||
return $shared_cache if (ref($shared_cache) eq 'HASH'); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
hm, we might not have a better choice here as we can't check something like if $shared_cache->{error}
if $shared_cache
is actually a string. I think the current way as you provided is fine
I was working on returning a consistent type. :) |
sure, no problem. If you have something better on top no problem to have another PR. |
See: https://progress.opensuse.org/issues/65840