@@ -0,0 +1,74 @@
3+// These tests verify that the Error function correctly handles various
4+// scenarios. These tests will not log anything.
10+func TestError(t *testing.T) {
11+ t.Run("returns early when client is nil", func(t *testing.T) {
12+ // This test verifies that when the PostHog client is not initialized
13+ // the Error function safely returns early without attempting to
14+ // enqueue any events. This is important during initialization or when
15+ // metrics are disabled, as we don't want the error reporting mechanism
16+ // itself to cause panics.
17+ originalClient := client
19+ client = originalClient
23+ Error("test error", "key", "value")
26+ t.Run("handles nil client without panicking", func(t *testing.T) {
27+ // This test covers various edge cases where the error value might be
28+ // nil, a string, or an error type.
29+ originalClient := client
31+ client = originalClient
37+ Error(newDefaultTestError("runtime error"), "key", "value")
40+ t.Run("handles error with properties", func(t *testing.T) {
41+ // This test verifies that the Error function can handle additional
42+ // key-value properties that provide context about the error. These
43+ // properties are typically passed when recovering from panics (i.e.,
44+ // panic name, function name).
46+ // Even with these additional properties, the function should handle
47+ // them gracefully without panicking.
48+ originalClient := client
50+ client = originalClient
57+ "source", "unit-test",
62+// newDefaultTestError creates a test error that mimics runtime panic
63+// errors. This helps us testing that the Error function can handle various
64+// error types, including those that might be passed from a panic recovery
66+func newDefaultTestError(s string) error {
72+func (e testError) Error() string {