helm-operator-plugins icon indicating copy to clipboard operation
helm-operator-plugins copied to clipboard

fix: error being silenced during apply

Open timonwong opened this issue 1 year ago • 2 comments

	defer func() {
		applyErr := u.Apply(ctx, obj)
   		// Problem: err is not assigned to return value  
		if err == nil && !apierrors.IsNotFound(applyErr) {
			err = applyErr
		}
	}()

timonwong avatar Sep 19 '24 03:09 timonwong

Nice catch! Although it feels like such issue should really be caught by unit tests. Could you maybe take a stab at adding such case?

sure! i'll then add a case for that

timonwong avatar Sep 19 '24 05:09 timonwong

Codecov Report

All modified and coverable lines are covered by tests :white_check_mark:

Project coverage is 79.67%. Comparing base (08ab7fb) to head (abbabcb). Report is 48 commits behind head on main.

:exclamation: There is a different number of reports uploaded between BASE (08ab7fb) and HEAD (abbabcb). Click for more details.

HEAD has 1 upload less than BASE
Flag BASE (08ab7fb) HEAD (abbabcb)
2 1
Additional details and impacted files
@@            Coverage Diff             @@
##             main     #395      +/-   ##
==========================================
- Coverage   85.06%   79.67%   -5.40%     
==========================================
  Files          19       31      +12     
  Lines        1346     1958     +612     
==========================================
+ Hits         1145     1560     +415     
- Misses        125      310     +185     
- Partials       76       88      +12     

:umbrella: View full report in Codecov by Sentry.
:loudspeaker: Have feedback on the report? Share it here.

codecov-commenter avatar Sep 19 '24 16:09 codecov-commenter

Any particular reason why the Apply operation can't be done at the end of the function instead of in a defer clause?

komish avatar Oct 08 '24 14:10 komish

Any particular reason why the Apply operation can't be done at the end of the function instead of in a defer clause?

Becasue the Apply() is for status update here. When early return (in case of error) from Reconcile loop, you need to set error conditions for your managed CR resources, the defer approch is more ideal than:

  1. use goto to handle them in a uniform way
  2. call Apply every time before return err

timonwong avatar Oct 09 '24 02:10 timonwong