Skip to content
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

Merged
merged 1 commit into from
Apr 22, 2020

Conversation

Amrysliu
Copy link
Contributor

t/24-worker-jobs.t Outdated Show resolved Hide resolved
t/24-worker-jobs.t Outdated Show resolved Hide resolved
@@ -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});
Copy link
Member

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

Copy link
Contributor

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.

Copy link
Contributor Author

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?

Copy link
Contributor

@Martchus Martchus Apr 20, 2020

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.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@okurz I remain the checking ref. Because sometimes the function return a string, if I only use $shared_cache->{error}, it will report a error message Can't use string ("xxx") as a HASH ref while "strict refs".
@Martchus I just added a return undef in do_asset_cacheing, is it enough?

Copy link
Contributor Author

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.

Copy link
Member

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};

Copy link
Contributor Author

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.

Copy link
Contributor Author

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.

Copy link
Contributor

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
Copy link

codecov bot commented Apr 20, 2020

Codecov Report

Merging #2960 into master will decrease coverage by 0.02%.
The diff coverage is 100.00%.

Impacted file tree graph

@@            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     
Impacted Files Coverage Δ
lib/OpenQA/Worker/Engines/isotovideo.pm 93.85% <100.00%> (+0.05%) ⬆️
lib/OpenQA/Worker/Job.pm 74.88% <0.00%> (-0.48%) ⬇️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update 1a52551...4179437. Read the comment docs.

@@ -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');
Copy link
Member

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.

Copy link
Member

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');
Copy link
Member

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

@okurz okurz merged commit d819309 into os-autoinst:master Apr 22, 2020
@Amrysliu
Copy link
Contributor Author

I was working on returning a consistent type. :)

@okurz
Copy link
Member

okurz commented Apr 23, 2020

sure, no problem. If you have something better on top no problem to have another PR.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

None yet

3 participants