Ejemplo
google.golang.org/grpc v1.82.0: status.Error
Muestra verificada para golang google.golang.org/grpc v1.82.0: status.Error. El contrato se ejecutó en go 1.26 · linux debian/x64 · docker y pasó.
sha256:eca4eb7c80cd9eed71bea3ace05edbb64c2308ce4c1e998476436049fcdc0b94
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 linux 24 · ubuntu · glibc 2.39 x64 go go go
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-10-12 |
Caso
HOW- Objetivo
- verify google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.82.0
- Paquetes
- Símbolos
-
- google.golang.org/grpc/status.Error
- Entorno
- go
- Creado
- 2026-10-12T08:18:18Z
Contrato
- status.Error returns nil when passed codes.OK.
- status.Error returns a non-nil error whose Error() method formats as 'rpc error: code = <Code> desc = <msg>' for non-OK codes.
- status.FromError extracts the matching status code and message from errors created by status.Error.
- errors.Is reports true for status errors created by status.Error with matching code and message.
- status.Error produces errors implementing the GRPCStatus() *status.Status 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 google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.82.0
Kind: HOW
Use EXACTLY these public packages and versions:
- pkg:golang/google.golang.org/grpc@v1.82.0
Demonstrate these symbols/APIs:
- google.golang.org/grpc/status.Error
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:815a49a359592144f4982f1c48f6cbf1cc980d63e244b8c18a2aa5e40a06c3d6","contract":["status.Error returns nil when passed codes.OK.","status.Error returns a non-nil error whose Error() method formats as 'rpc error: code = \u003cCode\u003e desc = \u003cmsg\u003e' for non-OK codes.","status.FromError extracts the matching status code and message from errors created by status.Error.","errors.Is reports true for status errors created by status.Error with matching code and message.","status.Error produces errors implementing the GRPCStatus() *status.Status interface."],"goal":"verify google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.82.0","kind":"HOW","packages":["pkg:golang/google.golang.org/grpc@v1.82.0"],"schemaVersion":1,"symbols":["google.golang.org/grpc/status.Error"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","language":"go","libc":"glibc","libcVersion":"2.39","moduleSystem":"go.mod","os":"linux","osVersionBucket":"24","packageManager":"go","runtime":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/grpc@v1.82.0"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/grpc@v1.82.0","symbols":["google.golang.org/grpc/status.Error"],"verifierAdapter":"golang@1"}
module example.com/statuserror
go 1.26.6
require google.golang.org/grpc v1.82.0
require (
golang.org/x/sys v0.43.0 // indirect
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 // indirect
google.golang.org/protobuf v1.36.11 // indirect
)
github.com/golang/protobuf v1.5.4 h1:i7eJL8qZTpSEXOPTxNKhASYpMn+8e5Q6AdndVa1dWek=
github.com/golang/protobuf v1.5.4/go.mod h1:lnTiLA8Wa4RWRcIUkrtSVa5nRhsEGBg48fD6rSs7xps=
github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8=
github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU=
golang.org/x/net v0.53.0 h1:d+qAbo5L0orcWAr0a9JweQpjXF19LMXJE8Ey7hwOdUA=
golang.org/x/net v0.53.0/go.mod h1:JvMuJH7rrdiCfbeHoo3fCQU24Lf5JJwT9W3sJFulfgs=
golang.org/x/sys v0.43.0 h1:Rlag2XtaFTxp19wS8MXlJwTvoh8ArU6ezoyFsMyCTNI=
golang.org/x/sys v0.43.0/go.mod h1:4GL1E5IUh+htKOUEOaiffhrAeqysfVGipDYzABqnCmw=
golang.org/x/text v0.36.0 h1:JfKh3XmcRPqZPKevfXVpI1wXPTqbkE5f7JA92a55Yxg=
golang.org/x/text v0.36.0/go.mod h1:NIdBknypM8iqVmPiuco0Dh6P5Jcdk8lJL0CUebqK164=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478 h1:RmoJA1ujG+/lRGNfUnOMfhCy5EipVMyvUE+KNbPbTlw=
google.golang.org/genproto/googleapis/rpc v0.0.0-20260414002931-afd174a4e478/go.mod h1:4Hqkh8ycfw05ld/3BWL7rJOSfebL2Q+DVDeRgYgxUU8=
google.golang.org/grpc v1.82.0 h1:vguDnZUPjE26w09A63VoxZPnvPjB5Riyc0mkXPFmAIU=
google.golang.org/grpc v1.82.0/go.mod h1:yzTZ1TB1Z3SG+LIYaI+WiE8D5+PZ3ArnrSp8zF3+/ZA=
google.golang.org/protobuf v1.36.11 h1:fV6ZwhNocDyBLK0dj+fg8ektcVegBBuEolpbTQyBNVE=
google.golang.org/protobuf v1.36.11/go.mod h1:HTf+CrKn2C3g5S8VImy6tdcUvCska2kB7j23XfzDpco=
package main
import (
"errors"
"fmt"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func main() {
// 1. status.Error with codes.OK returns nil
okErr := status.Error(codes.OK, "success")
fmt.Printf("codes.OK error is nil: %v\n", okErr == nil)
// 2. status.Error with non-OK code returns formatted error
notFoundErr := status.Error(codes.NotFound, "user not found")
fmt.Printf("error message: %v\n", notFoundErr.Error())
// 3. Inspecting the status code and message
if st, ok := status.FromError(notFoundErr); ok {
fmt.Printf("extracted code: %v, message: %s\n", st.Code(), st.Message())
}
// 4. Comparison using errors.Is
sameErr := status.Error(codes.NotFound, "user not found")
fmt.Printf("errors.Is matches same status error: %v\n", errors.Is(notFoundErr, sameErr))
}
{
"schemaVersion": 1,
"goal": "verify google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.82.0",
"kind": "HOW",
"packages": [
"pkg:golang/google.golang.org/grpc@v1.82.0"
],
"symbols": [
"google.golang.org/grpc/status.Error"
]
}
package main
import (
"errors"
"fmt"
"os"
"google.golang.org/grpc/codes"
"google.golang.org/grpc/status"
)
func main() {
// Assertion 1: status.Error returns nil when passed codes.OK.
if err := status.Error(codes.OK, "no error occurred"); err != nil {
fmt.Fprintf(os.Stderr, "FAIL assertion 1: expected nil for codes.OK, got: %v\n", err)
os.Exit(1)
}
if err := status.Error(codes.OK, ""); err != nil {
fmt.Fprintf(os.Stderr, "FAIL assertion 1: expected nil for codes.OK with empty message, got: %v\n", err)
os.Exit(1)
}
// Assertion 2: status.Error returns a non-nil error whose Error() method formats as 'rpc error: code = <Code> desc = <msg>' for non-OK codes.
testCases := []struct {
code codes.Code
msg string
want string
}{
{codes.NotFound, "resource not found", "rpc error: code = NotFound desc = resource not found"},
{codes.InvalidArgument, "invalid input parameter", "rpc error: code = InvalidArgument desc = invalid input parameter"},
{codes.PermissionDenied, "access denied", "rpc error: code = PermissionDenied desc = access denied"},
{codes.Internal, "internal server error", "rpc error: code = Internal desc = internal server error"},
{codes.Unavailable, "service temporarily unavailable", "rpc error: code = Unavailable desc = service temporarily unavailable"},
}
for _, tc := range testCases {
err := status.Error(tc.code, tc.msg)
if err == nil {
fmt.Fprintf(os.Stderr, "FAIL assertion 2: expected non-nil error for code %v\n", tc.code)
os.Exit(1)
}
if got := err.Error(); got != tc.want {
fmt.Fprintf(os.Stderr, "FAIL assertion 2: err.Error() = %q, want %q\n", got, tc.want)
os.Exit(1)
}
}
// Assertion 3: status.FromError extracts the matching status code and message from errors created by status.Error.
for _, tc := range testCases {
err := status.Error(tc.code, tc.msg)
st, ok := status.FromError(err)
if !ok {
fmt.Fprintf(os.Stderr, "FAIL assertion 3: status.FromError(%v) returned ok=false\n", err)
os.Exit(1)
}
if gotCode := st.Code(); gotCode != tc.code {
fmt.Fprintf(os.Stderr, "FAIL assertion 3: st.Code() = %v, want %v\n", gotCode, tc.code)
os.Exit(1)
}
if gotMsg := st.Message(); gotMsg != tc.msg {
fmt.Fprintf(os.Stderr, "FAIL assertion 3: st.Message() = %q, want %q\n", gotMsg, tc.msg)
os.Exit(1)
}
if gotCode := status.Code(err); gotCode != tc.code {
fmt.Fprintf(os.Stderr, "FAIL assertion 3: status.Code(err) = %v, want %v\n", gotCode, tc.code)
os.Exit(1)
}
}
// Assertion 4: errors.Is reports true for status errors created by status.Error with matching code and message.
errA := status.Error(codes.NotFound, "entity missing")
errB := status.Error(codes.NotFound, "entity missing")
errDiffMsg := status.Error(codes.NotFound, "other entity")
errDiffCode := status.Error(codes.AlreadyExists, "entity missing")
if !errors.Is(errA, errB) {
fmt.Fprintf(os.Stderr, "FAIL assertion 4: expected errors.Is(errA, errB) == true for identical status errors\n")
os.Exit(1)
}
if errors.Is(errA, errDiffMsg) {
fmt.Fprintf(os.Stderr, "FAIL assertion 4: expected errors.Is == false for different messages\n")
os.Exit(1)
}
if errors.Is(errA, errDiffCode) {
fmt.Fprintf(os.Stderr, "FAIL assertion 4: expected errors.Is == false for different codes\n")
os.Exit(1)
}
if errors.Is(errA, errors.New("entity missing")) {
fmt.Fprintf(os.Stderr, "FAIL assertion 4: expected errors.Is == false for standard error\n")
os.Exit(1)
}
// Assertion 5: status.Error produces errors implementing the GRPCStatus() *status.Status interface.
type grpcStatusCarrier interface {
GRPCStatus() *status.Status
}
statusErr := status.Error(codes.FailedPrecondition, "condition not met")
carrier, ok := statusErr.(grpcStatusCarrier)
if !ok {
fmt.Fprintf(os.Stderr, "FAIL assertion 5: status.Error does not implement GRPCStatus() *status.Status\n")
os.Exit(1)
}
if carrier.GRPCStatus() == nil {
fmt.Fprintf(os.Stderr, "FAIL assertion 5: GRPCStatus() returned nil\n")
os.Exit(1)
}
if gotCode := carrier.GRPCStatus().Code(); gotCode != codes.FailedPrecondition {
fmt.Fprintf(os.Stderr, "FAIL assertion 5: carrier.GRPCStatus().Code() = %v, want %v\n", gotCode, codes.FailedPrecondition)
os.Exit(1)
}
if gotMsg := carrier.GRPCStatus().Message(); gotMsg != "condition not met" {
fmt.Fprintf(os.Stderr, "FAIL assertion 5: carrier.GRPCStatus().Message() = %q, want %q\n", gotMsg, "condition not met")
os.Exit(1)
}
fmt.Println("All contract assertions verified successfully.")
}
Seeder de origen
anónimo