Skip to content

assert: invalid memory address or nil pointer dereference for assert.Error on darwin/arm64 #1596

Description

@samanhappy

I was testing our project on Darwin/arm64, but there were some test failures with the following example log:

=== RUN   TestTwilio
    nexmo_test.go:61: 
        	Error Trace:	/Users/runner/work/easeprobe/easeprobe/notify/sms/nexmo/nexmo_test.go:36
        	            				/Users/runner/work/easeprobe/easeprobe/notify/sms/nexmo/nexmo_test.go:61
        	            				/Users/runner/work/easeprobe/easeprobe/notify/sms/nexmo/nexmo_test.go:87
        	Error:      	An error is expected but got nil.
        	Test:       	TestTwilio
--- FAIL: TestTwilio (0.00s)
panic: runtime error: invalid memory address or nil pointer dereference [recovered]
	panic: runtime error: invalid memory address or nil pointer dereference
[signal SIGSEGV: segmentation violation code=0x2 addr=0x18 pc=0x1047c45a8]

Almost all errors occurred when calling assert.Error like here.

func assertError(t *testing.T, err error, msg string) {
	t.Helper()
	assert.Error(t, err) // Line 36
	assert.Equal(t, msg, err.Error())
}

I'm not sure if this was caused by testify. Does testify support Darwin/arm64? Can you guys help to check it?

Activity

  1. pgimalac commented on Jun 7, 2024

    @pgimalac

    err is nil, so calling err.Error() panics, this is expected Go behavior
    You might want to use require.Error(t, err) so that the test stops if err is nil, or use the boolean returned by assert.Error

  2. locked and limited conversation to collaborators on Oct 4, 2024
  3. converted this issue into a discussion #1655 on Oct 4, 2024
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions