CodeSampleX

Sample

google.golang.org/grpc v1.31.0: status.Error

Verified sample for golang google.golang.org/grpc v1.31.0: status.Error. The contract ran on go 1.26 · linux debian/x64 · docker and passed.

sha256:d17826b96c47d250bac435d5b486221146c7f2cbac946eebe329bd691e6682fc

This network offers one thing: a sample that builds. It ran the sample in a sandbox and kept the signed receipt. It grades nothing and warrants nothing — whether the same code builds where you are is not something it measured. How many distinct signing keys filed a passing contract receipt. One is the author alone; more than one means somebody else built it too. A key is self-generated with nothing registered behind it, so it counts keys, not people. MIT-0

Execution evidence

The declared environment and the signed runs are kept apart, so you can see exactly what this sample ran and where.

Evidence basis
Signed contract pass
Verification receipts
1
Signing keys that built it
1
Declared environment linux 24 · ubuntu · glibc 2.39 x64 go

Verification-run environments

Environment Contract Stages Run
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-13

Case

HOW
Goal
verify google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.31.0
Packages
Symbols
  • google.golang.org/grpc/status.Error
Created
2026-10-13T12:41:58Z

Contract

  1. status.Error returns nil when passed codes.OK.
  2. status.Error returns a non-nil error whose Error() method formats as 'rpc error: code = <Code> desc = <msg>' for non-OK codes.
  3. status.FromError extracts the matching status code and message from errors created by status.Error.
  4. errors.Is reports true for status errors created by status.Error with matching code and message.
  5. status.Error produces errors implementing the GRPCStatus() *status.Status interface.

Files

  • PROMPT.md
  • csx.json
  • go.mod
  • go.sum
  • main.go
  • spec.json
  • test/contract.go

Download the source artifact (tar.gz)

Source

PROMPT.md
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.31.0
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/google.golang.org/grpc@v1.31.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.
csx.json
{"case":{"caseId":"case:sha256:354e1b2010849d86d54a36c22937b4f3dcb27430627d178c72a886ac71f2f2f3","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.31.0","kind":"HOW","packages":["pkg:golang/google.golang.org/grpc@v1.31.0"],"schemaVersion":1,"symbols":["google.golang.org/grpc/status.Error"]},"contractCommand":["go","run","./test"],"environment":{"arch":"x64","distro":"ubuntu","ecosystem":"golang","libc":"glibc","libcVersion":"2.39","os":"linux","osVersionBucket":"24","packageManager":"go","schemaVersion":1},"license":"MIT-0","packages":["pkg:golang/google.golang.org/grpc@v1.31.0"],"schemaVersion":1,"subject":"pkg:golang/google.golang.org/grpc@v1.31.0","symbols":["google.golang.org/grpc/status.Error"],"verifierAdapter":"golang@1"}
go.mod
module example.com/statuserror

go 1.26.6

require google.golang.org/grpc v1.31.0

require (
	github.com/golang/protobuf v1.3.3 // indirect
	google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 // indirect
)
go.sum
cloud.google.com/go v0.26.0/go.mod h1:aQUYkXzVsufM+DwF1aE+0xfcU+56JwCaLick0ClmMTw=
github.com/BurntSushi/toml v0.3.1/go.mod h1:xHWCNGjB5oqiDr8zfno3MHue2Ht5sIBksp03qcyfWMU=
github.com/census-instrumentation/opencensus-proto v0.2.1/go.mod h1:f6KPmirojxKA12rnyqOA5BBL4O983OfeGPqjHWSTneU=
github.com/client9/misspell v0.3.4/go.mod h1:qj6jICC3Q7zFZvVWo7KLAzC3yx5G7kyvSDkc90ppPyw=
github.com/cncf/udpa/go v0.0.0-20191209042840-269d4d468f6f/go.mod h1:M8M6+tZqaGXZJjfX53e64911xZQV5JYwmTeXPW+k8Sc=
github.com/envoyproxy/go-control-plane v0.9.0/go.mod h1:YTl/9mNaCwkRvm6d1a2C3ymFceY/DCBVvsKhRF0iEA4=
github.com/envoyproxy/go-control-plane v0.9.4/go.mod h1:6rpuAdCZL397s3pYoYcLgu1mIlRU8Am5FuJP05cCM98=
github.com/envoyproxy/protoc-gen-validate v0.1.0/go.mod h1:iSmxcyjqTsJpI2R4NaDN7+kN2VEUnK/pcBlmesArF7c=
github.com/golang/glog v0.0.0-20160126235308-23def4e6c14b/go.mod h1:SBH7ygxi8pfUlaOkMMuAQtPIUF8ecWP5IEl/CR7VP2Q=
github.com/golang/mock v1.1.1/go.mod h1:oTYuIxOrZwtPieC+H1uAHpcLFnEyAGVDL/k47Jfbm0A=
github.com/golang/protobuf v1.2.0/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.2/go.mod h1:6lQm79b+lXiMfvg/cZm0SGofjICqVBUtrP5yJMmIC1U=
github.com/golang/protobuf v1.3.3 h1:gyjaxf+svBWX08ZjK86iN9geUJF0H6gp2IRKX6Nf6/I=
github.com/golang/protobuf v1.3.3/go.mod h1:vzj43D7+SQXF/4pzW/hwtAqwc6iTitCiVSaWz5lYuqw=
github.com/google/go-cmp v0.2.0/go.mod h1:oXzfMopK8JAjlY9xF4vHSVASa0yLyX7SntLO5aqRK0M=
github.com/google/go-cmp v0.4.0 h1:xsAVV57WRhGj6kEIi8ReJzQlHHqcBYCElAvkovg3B/4=
github.com/google/go-cmp v0.4.0/go.mod h1:v8dTdLbMG2kIc/vJvl+f65V22dbkXbowE6jgT/gNBxE=
github.com/prometheus/client_model v0.0.0-20190812154241-14fe0d1b01d4/go.mod h1:xMI15A0UPsDsEKsMN9yxemIoYk6Tm2C1GtYGdfGttqA=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
golang.org/x/lint v0.0.0-20190313153728-d0100b6bd8b3/go.mod h1:6SW0HCj/g11FgYtHlgUYUwCkIfeOF89ocIRzGO/8vkc=
golang.org/x/net v0.0.0-20180724234803-3673e40ba225/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20180826012351-8a410e7b638d/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190213061140-3a22650c66bd/go.mod h1:mL1N/T3taQHkDXs73rZJwtUhF3w3ftmwwsq0BUmARs4=
golang.org/x/net v0.0.0-20190311183353-d8887717615a h1:oWX7TPOiFAMXLq8o0ikBYfCJVlRHBcsciT5bXOrH628=
golang.org/x/net v0.0.0-20190311183353-d8887717615a/go.mod h1:t9HGtf8HONx5eT2rtn7q6eTqICYqUVnKs3thJo3Qplg=
golang.org/x/oauth2 v0.0.0-20180821212333-d2e6202438be/go.mod h1:N/0e6XlmueqKjAGxoOufVs8QHGRruUQn6yWY3a++T0U=
golang.org/x/sync v0.0.0-20180314180146-1d60e4601c6f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20181108010431-42b317875d0f/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM=
golang.org/x/sys v0.0.0-20180830151530-49385e6e1522/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a h1:1BGLXjeY4akVXGgbC9HugT3Jv3hCI0z56oJR5vAMgBU=
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY=
golang.org/x/text v0.3.0 h1:g61tztE5qeGQ89tm6NTjjM9VPIm088od1l6aSorWRWg=
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ=
golang.org/x/tools v0.0.0-20190114222345-bf090417da8b/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ=
golang.org/x/tools v0.0.0-20190226205152-f727befe758c/go.mod h1:9Yl7xja0Znq3iFh3HoIrodX9oNMXvdceNzlUR8zjMvY=
golang.org/x/tools v0.0.0-20190311212946-11955173bddd/go.mod h1:LCzVGOaR6xXOjkQ3onu1FJEFr0SW1gC7cKk1uF8kGRs=
golang.org/x/tools v0.0.0-20190524140312-2c0ae7006135/go.mod h1:RgjU9mgBXZiqYHBnxXauZ1Gv1EHHAz9KjViQ78xBX0Q=
golang.org/x/xerrors v0.0.0-20191204190536-9bdfabe68543/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0=
google.golang.org/appengine v1.1.0/go.mod h1:EbEs0AVv82hx2wNQdGPgUI5lhzA/G0D9YwlJXL52JkM=
google.golang.org/appengine v1.4.0/go.mod h1:xpcJRLb0r/rnEns0DIKYYv+WjYCduHsrkT7/EB5XEv4=
google.golang.org/genproto v0.0.0-20180817151627-c66870c02cf8/go.mod h1:JiN7NxoALGmiZfu7CAH4rXhgtRTLTxftemlI0sWmxmc=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55 h1:gSJIx1SDwno+2ElGhA4+qG2zF97qiUzTM+rQ0klBOcE=
google.golang.org/genproto v0.0.0-20190819201941-24fa4b261c55/go.mod h1:DMBHOl98Agz4BDEuKkezgsaosCRResVns1a3J2ZsMNc=
google.golang.org/grpc v1.19.0/go.mod h1:mqu4LbDTu4XGKhr4mRzUsmM4RtVoemTSY81AxZiDr8c=
google.golang.org/grpc v1.23.0/go.mod h1:Y5yQAOtifL1yxbo5wqy6BxZv8vAUGQwXBOALyacEbxg=
google.golang.org/grpc v1.25.1/go.mod h1:c3i+UQWmh7LiEpx4sFZnkU36qjEYZ0imhYfXVyQciAY=
google.golang.org/grpc v1.31.0 h1:T7P4R73V3SSDPhH7WW7ATbfViLtmamH0DKrP3f9AuDI=
google.golang.org/grpc v1.31.0/go.mod h1:N36X2cJ7JwdamYAgDz+s+rVMFjt3numwzf/HckM8pak=
honnef.co/go/tools v0.0.0-20190102054323-c2f93a96b099/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
honnef.co/go/tools v0.0.0-20190523083050-ea95bdfd59fc/go.mod h1:rf3lG4BRIbNafJWhAfAdb/ePZxsR/4RtNHQocxwk9r4=
main.go
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))
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify google.golang.org/grpc/status.Error in pkg:golang/google.golang.org/grpc@v1.31.0",
  "kind": "HOW",
  "packages": [
    "pkg:golang/google.golang.org/grpc@v1.31.0"
  ],
  "symbols": [
    "google.golang.org/grpc/status.Error"
  ]
}
test/contract.go
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.")
}

Origin Seeder

anonymous