Ejemplo
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543: As
Muestra verificada para golang golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543: As. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y…
sha256:dc94975ebaea6e26c0ad9f2d3caa445ec52eb19cf64fd491bac94d8e4c4fa66a
Esta red ofrece una sola cosa: una muestra que compila. La ejecutó en un sandbox y guardó el recibo firmado. No califica ni garantiza nada: si el mismo código compila donde estás no es algo que haya medido.
Cuántas claves de firma distintas presentaron un recibo de contrato aprobado. Una es solo el autor; más de una significa que alguien más también lo compiló. Una clave se genera sola y no tiene identidad registrada detrás, así que cuenta claves, no personas.
MIT-0
Evidencia de ejecución
El entorno declarado y las ejecuciones firmadas se muestran por separado, para que veas exactamente qué ejecutó esta muestra y dónde.
- Base de evidencia
- Contrato firmado aprobado
- Recibos de verificación
- 1
- Claves de firma que lo compilaron
- 1
Entorno declarado
go 1.26 linux 24 · ubuntu · glibc 2.39 x64 go 1.26 go go 1
Entornos de las ejecuciones de verificación
| Entorno | Contrato | Etapas | Ejecución |
|---|---|---|---|
| go 1.26 · linux debian/x64 · docker ed25519:c1973797be207ac4 | PASS | compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS CONTAINER_RUN · golang@1golang:1.26@sha256:e30143be198a… |
2026-09-05 |
Caso
HOW- Objetivo
- verify xerrors.As in pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543
- Símbolos
-
- xerrors.As
- Entorno
- go 1.26.6
- Creado
- 2026-09-05T05:41:38Z
Contrato
- xerrors.As finds and extracts a matching pointer to struct in an error chain
- xerrors.As returns false and leaves target unchanged when type does not match
- xerrors.As finds and extracts an error implementing a target interface
- xerrors.As supports custom As method on error types
- xerrors.As panics when target is nil or not a pointer to error or interface
Archivos
- PROMPT.md
- csx.json
- go.mod
- go.sum
- main.go
- spec.json
- test/contract.go
Código fuente
Clean-room public code sample — generation instructions
Write a brand-new, minimal, self-contained code sample in this clean-room directory.
Do not copy, paraphrase, or reference any existing project source. Work only from this spec.
A csx.json manifest scaffold already exists. Do not recreate it from memory. Preserve its case.goal, packages and symbols; fill its empty case.contract with exact assertions and correct its environment, commands and verifierAdapter for the files you generate.
Goal: verify xerrors.As in pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543
Demonstrate these symbols/APIs:
- xerrors.As
Required runtime conditions:
- ecosystem: golang
- language: go
- packageManager: go@1.26.6
- runtime: go@1.26.6
Rules:
- One focused purpose; the smallest project that proves the goal.
- Include a contract test (test/contract.*) that runs OFFLINE and exits 0 exactly when the goal behavior works.
- Pin every dependency with a lockfile so resolution is reproducible.
- No secrets, credentials, or tokens. No real URLs (only example.com or localhost). No absolute paths.
- No personal names, emails, company names, or project identifiers of any kind.
- No binaries and no generated output (node_modules, dist, target, venv, .git, .env).
- Keep it under 200 files and 256KB packed.
{"case":{"caseId":"case:sha256:3ae202748a0bb0f63b724d5a6d17919ab176ad03d33dfb8086d0bbb4622b4587","contract":["xerrors.As finds and extracts a matching pointer to struct in an error chain","xerrors.As returns false and leaves target unchanged when type does not match","xerrors.As finds and extracts an error implementing a target interface","xerrors.As supports custom As method on error types","xerrors.As panics when target is nil or not a pointer to error or interface"],"goal":"verify xerrors.As in pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543","kind":"HOW","packages":["pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543"],"schemaVersion":1,"symbols":["xerrors.As"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","packageManagerVersion":"1.26.6","runtime":"go","runtimeVersion":"1.26.6","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543"],"schemaVersion":1,"subject":"pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543","symbols":["xerrors.As"],"verifierAdapter":"golang@1"}
module example.com/sample
go 1.22.0
require golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543 h1:E7g+9GITq07hpfrRu66IVDexMakfv52eLZ2CXBWiKr4=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
package main
import (
"fmt"
"os"
"golang.org/x/xerrors"
)
// ItemNotFoundError indicates that a requested item was not found.
type ItemNotFoundError struct {
Resource string
ID string
}
func (e *ItemNotFoundError) Error() string {
return fmt.Sprintf("%s with ID %q was not found", e.Resource, e.ID)
}
// ResourceIdentifier allows querying the resource name of an error.
type ResourceIdentifier interface {
Error() string
}
func findItem(id string) error {
return &ItemNotFoundError{
Resource: "document",
ID: id,
}
}
func processItem(id string) error {
if err := findItem(id); err != nil {
return xerrors.Errorf("processing item %s failed: %w", id, err)
}
return nil
}
func main() {
err := processItem("doc-42")
if err == nil {
fmt.Println("success")
return
}
fmt.Printf("Encountered error: %v\n", err)
// Use xerrors.As to inspect and extract the typed ItemNotFoundError
var notFoundErr *ItemNotFoundError
if xerrors.As(err, ¬FoundErr) {
fmt.Printf("Handled ItemNotFoundError: resource=%s id=%s\n", notFoundErr.Resource, notFoundErr.ID)
} else {
fmt.Fprintf(os.Stderr, "Expected ItemNotFoundError in error chain\n")
os.Exit(1)
}
// Use xerrors.As to check interface implementation
var resErr ResourceIdentifier
if xerrors.As(err, &resErr) {
fmt.Printf("Handled ResourceIdentifier interface: %s\n", resErr.Error())
}
}
{
"schemaVersion": 1,
"goal": "verify xerrors.As in pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543",
"kind": "HOW",
"packages": [
"pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543"
],
"symbols": [
"xerrors.As"
],
"runtimeConditions": {
"ecosystem": "golang",
"language": "go",
"packageManager": "go@1.26.6",
"runtime": "go@1.26.6"
}
}
package main
import (
"fmt"
"os"
"golang.org/x/xerrors"
)
type appError struct {
code int
detail string
}
func (e *appError) Error() string {
return fmt.Sprintf("app error %d: %s", e.code, e.detail)
}
func (e *appError) StatusCode() int {
return e.code
}
type otherError struct {
reason string
}
func (e *otherError) Error() string {
return fmt.Sprintf("other error: %s", e.reason)
}
type statusCoder interface {
StatusCode() int
}
type customErrorTarget struct {
resolved int
}
func (e *customErrorTarget) Error() string {
return fmt.Sprintf("custom error target code %d", e.resolved)
}
type customAsError struct {
customCode int
}
func (e *customAsError) Error() string {
return fmt.Sprintf("custom as error code %d", e.customCode)
}
func (e *customAsError) As(target interface{}) bool {
if p, ok := target.(**customErrorTarget); ok {
*p = &customErrorTarget{resolved: e.customCode}
return true
}
return false
}
func assertPanic(name string, f func()) {
defer func() {
if r := recover(); r == nil {
fmt.Fprintf(os.Stderr, "FAIL: %s expected panic, got none\n", name)
os.Exit(1)
}
}()
f()
}
func main() {
// Assertion 1: xerrors.As finds and extracts a matching pointer to struct in an error chain
origErr := &appError{code: 404, detail: "resource missing"}
chain := xerrors.Errorf("outer wrap: %w", xerrors.Errorf("inner wrap: %w", origErr))
var matchedAppErr *appError
if !xerrors.As(chain, &matchedAppErr) {
fmt.Fprintf(os.Stderr, "FAIL: xerrors.As failed to match *appError in chain\n")
os.Exit(1)
}
if matchedAppErr != origErr {
fmt.Fprintf(os.Stderr, "FAIL: target pointer mismatch: got %p, want %p\n", matchedAppErr, origErr)
os.Exit(1)
}
if matchedAppErr.code != 404 {
fmt.Fprintf(os.Stderr, "FAIL: unexpected code: got %d, want 404\n", matchedAppErr.code)
os.Exit(1)
}
// Assertion 2: xerrors.As returns false and leaves target unchanged when type does not match
var mismatch *otherError
if xerrors.As(chain, &mismatch) {
fmt.Fprintf(os.Stderr, "FAIL: xerrors.As unexpectedly matched *otherError\n")
os.Exit(1)
}
if mismatch != nil {
fmt.Fprintf(os.Stderr, "FAIL: mismatch target should remain nil, got %v\n", mismatch)
os.Exit(1)
}
// Assertion 3: xerrors.As finds and extracts an error implementing a target interface
var sc statusCoder
if !xerrors.As(chain, &sc) {
fmt.Fprintf(os.Stderr, "FAIL: xerrors.As failed to match statusCoder interface\n")
os.Exit(1)
}
if sc == nil || sc.StatusCode() != 404 {
fmt.Fprintf(os.Stderr, "FAIL: statusCoder returned invalid status: %v\n", sc)
os.Exit(1)
}
// Assertion 4: xerrors.As supports custom As method on error types
customErr := &customAsError{customCode: 99}
customChain := xerrors.Errorf("wrap: %w", customErr)
var customTarget *customErrorTarget
if !xerrors.As(customChain, &customTarget) {
fmt.Fprintf(os.Stderr, "FAIL: xerrors.As failed on custom As implementation\n")
os.Exit(1)
}
if customTarget == nil || customTarget.resolved != 99 {
fmt.Fprintf(os.Stderr, "FAIL: custom target mismatch: got %v\n", customTarget)
os.Exit(1)
}
// Assertion 5: xerrors.As panics when target is nil or not a pointer to error or interface
assertPanic("nil target", func() {
xerrors.As(chain, nil)
})
assertPanic("non-pointer target", func() {
xerrors.As(chain, appError{})
})
fmt.Println("PASS: pkg:golang/golang.org/x/xerrors@v0.0.0-20191204190536-9bdfabe68543 contract passed")
}
Seeder de origen
anónimo