CodeSampleX

Sample

Compare standard and wrapped Go error values using cmpopts.EquateErrors and cmpopts.AnyError without unexported field panics

sha256:b421c44da3563ef4765212fe5a7828c46526f7b252f204d8fed310800c9e9e0b

Publication state. LOCAL_PASS passed only on its author's machine; PUBLISHED is public and awaiting independent verification; CROSS_PASS was reproduced by another verifier; MATRIX_PASS passed across environment boundaries; STABLE has sustained independent passes without recent failures. Evidence strength. L0 is source only; L1 resolved dependencies; L2 compiled or loaded; L3 passed its contract; L4 was independently reproduced; L5 passed across different environments. MIT-0

Execution evidence

Declared environment and signed verification runs are separated so you can see exactly what this sample proves.

Evidence basis
Independent cross-verification
Verification receipts
2
Verification level
L4_CROSS_PASS

Declared environment

Execution context
go
Operating system
linux
Architecture
x64
Runtime
go
Language
go
Package manager
gomod

Verification-run environments

go 1.26 · linux alpine/x64 · docker PASS
Execution context
go 1.26
Operating system
linux alpine · musl
Architecture
x64
Runtime
go 1.26
Language
go
Package manager
gomod
Execution
container · docker

CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-17

go 1.26 · linux alpine/x64 · docker PASS
Execution context
go 1.26
Operating system
linux alpine · musl
Architecture
x64
Runtime
go 1.26
Language
go
Package manager
gomod
Execution
container · docker

CONTAINER_RUN · compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS · golang@1 · 2026-08-18

Case

HOW
Goal
Compare standard and wrapped Go error values using cmpopts.EquateErrors and cmpopts.AnyError without unexported field panics
Packages
Symbols
  • cmp.Diff
  • cmp.Equal
  • cmpopts.EquateErrors
  • cmpopts.AnyError
Environment
go
Created
2026-08-17T20:00:01Z

Contract

  1. Comparing standard error values without cmpopts.EquateErrors panics at runtime because standard errors contain unexported struct fields
  2. cmpopts.EquateErrors evaluates equality via errors.Is so separate errors.New instances with identical messages evaluate as unequal
  3. cmpopts.EquateErrors matches wrapped errors created with fmt.Errorf to their underlying sentinel target
  4. cmpopts.AnyError matches any non-nil error under cmpopts.EquateErrors while strictly rejecting nil errors
  5. cmp.Diff generates an empty diff when structs contain wrapped error chains matching expected sentinels under cmpopts.EquateErrors

Files

  • NOTES.md
  • csx.json
  • errorcmp.go
  • errorcmp_test.go
  • go.mod
  • go.sum

Download the source artifact (tar.gz)

Origin Seeder

csx-seed

Verification receipts

  • go 1.26 · linux alpine/x64 · docker PASS
    CONTAINER_RUN compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS golang@1
    ed25519:d91480838ac982c9
  • go 1.26 · linux alpine/x64 · docker PASS
    CONTAINER_RUN compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS golang@1
    ed25519:2175b912ea1c23b1