Repository: snowflakedb/gosnowflake
Pull request #1012 (2023-12-21 08:15:40)

SNOW-994698 cover corner cases where an unexpected non APIerror occurs during HeadObject
 to see if it fixes 1008

### Description
Please explain the changes you made here.

### Checklist
- [ ] Code compiles correctly
- [ ] Run ``make fmt`` to fix inconsistent formats
- [ ] Run ``make lint`` to get lint errors and fix all of them
- [ ] Created tests which fail without the change (if possible)
- [ ] All tests passing
- [ ] Extended the README / documentation, if necessary


codecov[bot]: ## [Codecov](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1012?src=pr&el=h1&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) Report
All modified and coverable lines are covered by tests :white_check_mark:
> Comparison is base [(`4b69339`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/commit/4b6933989a6119f330f9d02e7ff848fac9d8e3d0?el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) 82.77% compared to head [(`112c9eb`)](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1012?src=pr&el=desc&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb) 80.71%.


<details><summary>Additional details and impacted files</summary>


```diff
@@            Coverage Diff             @@
##           master    #1012      +/-   ##
==========================================
- Coverage   82.77%   80.71%   -2.07%     
==========================================
  Files          50       49       -1     
  Lines        9708     9710       +2     
==========================================
- Hits         8036     7837     -199     
- Misses       1672     1873     +201     
```



</details>

[:umbrella: View full report in Codecov by Sentry](https://app.codecov.io/gh/snowflakedb/gosnowflake/pull/1012?src=pr&el=continue&utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).   
:loudspeaker: Have feedback on the report? [Share it here](https://about.codecov.io/codecov-pr-comment-feedback/?utm_medium=referral&utm_source=github&utm_content=comment&utm_campaign=pr+comments&utm_term=snowflakedb).


Patch:
diff --git a/s3_storage_client.go b/s3_storage_client.go
index 33be11f..0939309 100644
--- a/s3_storage_client.go
+++ b/s3_storage_client.go
@@ -89,6 +89,9 @@ func (util *snowflakeS3Client) getFileHeader(meta *fileMetadata, filename string
 			meta.lastError = err
 			return nil, fmt.Errorf("error while retrieving header")
 		}
+		meta.resStatus = errStatus
+		meta.lastError = err
+		return nil, fmt.Errorf("unexpected error while retrieving header: %v", err)
 	}
 
 	meta.resStatus = uploaded


Test patch:
diff --git a/assert_test.go b/assert_test.go
index b38c965..871c43c 100644
--- a/assert_test.go
+++ b/assert_test.go
@@ -18,6 +18,10 @@ func assertNilF(t *testing.T, actual any, descriptions ...string) {
 	fatalOnNonEmpty(t, validateNil(actual, descriptions...))
 }
 
+func assertNotNilE(t *testing.T, actual any, descriptions ...string) {
+	errorOnNonEmpty(t, validateNotNil(actual, descriptions...))
+}
+
 func assertNotNilF(t *testing.T, actual any, descriptions ...string) {
 	fatalOnNonEmpty(t, validateNotNil(actual, descriptions...))
 }
diff --git a/s3_storage_client_test.go b/s3_storage_client_test.go
index ca942dc..e85920c 100644
--- a/s3_storage_client_test.go
+++ b/s3_storage_client_test.go
@@ -285,6 +285,21 @@ func TestGetHeaderUnexpectedError(t *testing.T) {
 	}
 }
 
+func TestGetHeaderNonApiError(t *testing.T) {
+	meta := fileMetadata{
+		client:    s3.New(s3.Options{}),
+		stageInfo: &execResponseStageInfo{Location: ""},
+		mockHeader: mockHeaderAPI(func(ctx context.Context, params *s3.HeadObjectInput, optFns ...func(*s3.Options)) (*s3.HeadObjectOutput, error) {
+			return nil, errors.New("something went wrong here")
+		}),
+	}
+
+	header, err := new(snowflakeS3Client).getFileHeader(&meta, "file.txt")
+	assertNilE(t, header, fmt.Sprintf("expected header to be nil, actual: %v", header))
+	assertNotNilE(t, err, "expected err to not be nil")
+	assertEqualE(t, meta.resStatus, errStatus, fmt.Sprintf("expected %v result status for non-APIerror, got: %v", errStatus, meta.resStatus))
+}
+
 func TestGetHeaderNotFoundError(t *testing.T) {
 	meta := fileMetadata{
 		client:    s3.New(s3.Options{}),