sourcegraph/lib/errors/BUILD.bazel
Varun Gandhi 2c3e813a31
chore: Add tests documenting error invariants (#62992)
Based on the [discussion in Slack](https://sourcegraph.slack.com/archives/C02UC4WUX1Q/p1717067410264679),
 thought it would be useful to solidify the invariants that hold
between errors.As, errors.Is and errors.HasType
(and provide counter-examples for things which you think
ought to hold but don't actually hold) in code itself, instead of 
just via docs. So this PR adds property-based tests for
quickly generating different kinds of error shapes, and check
which invariants hold and which ones don't.

It also adds better documentation for errors.Is and errors.As
2024-06-03 19:46:53 +08:00

41 lines
995 B
Python

load("//dev:go_defs.bzl", "go_test")
load("@io_bazel_rules_go//go:def.bzl", "go_library")
go_library(
name = "errors",
srcs = [
"cockroach.go",
"errors.go",
"filter.go",
"multi_error.go",
"postgres.go",
"warning.go",
],
importpath = "github.com/sourcegraph/sourcegraph/lib/errors",
tags = [TAG_INFRA_DEVINFRA],
visibility = ["//visibility:public"],
deps = [
"@com_github_cockroachdb_errors//:errors",
"@com_github_cockroachdb_redact//:redact",
"@com_github_jackc_pgconn//:pgconn",
],
)
go_test(
name = "errors_test",
timeout = "short",
srcs = [
"errors_test.go",
"filter_test.go",
"invariants_test.go",
"warning_test.go",
],
embed = [":errors"],
tags = [TAG_INFRA_DEVINFRA],
deps = [
"@com_github_stretchr_testify//assert",
"@com_github_stretchr_testify//require",
"@net_pgregory_rapid//:rapid",
],
)