CodeSampleX

Beispiel

github.com/pkg/errors v0.9.1

Verifiziertes Beispiel für golang github.com/pkg/errors v0.9.1. Der Vertrag lief auf go 1.26 · linux alpine/x64 · docker und bestand.

sha256:d05be37f7de04833720bbb4de694b8c60f138cc04d3d9ca948d20bb55f2a3309

Dieses Netzwerk bietet eine Sache: ein Sample, das baut. Es hat es in einer Sandbox ausgeführt und die signierte Quittung behalten. Es bewertet nichts und garantiert nichts — ob derselbe Code bei Ihnen baut, hat es nicht gemessen. Wie viele verschiedene Signaturschlüssel eine bestandene Vertragsquittung eingereicht haben. Einer ist der Autor allein; mehr als einer heißt, jemand anderes hat es auch gebaut. Ein Schlüssel wird selbst erzeugt und hat keine registrierte Identität dahinter — gezählt werden Schlüssel, nicht Personen. MIT-0

Ausführungsbelege

Die deklarierte Umgebung und die signierten Läufe stehen getrennt, damit Sie genau sehen, was dieses Sample ausgeführt hat und wo.

Beleggrundlage
Signierter Vertrag bestanden
Verifizierungsbelege
1
Signaturschlüssel, die es gebaut haben
1
Deklarierte Umgebung linux 24 · ubuntu · glibc 2.39 x64 go

Umgebungen der Verifizierungsläufe

Umgebung Contract Stufen Lauf
go 1.26 · linux alpine/x64 · docker ed25519:c1973797be207ac4 PASS compile:SKIPPED · contract:PASS · load:PASS · resolve:PASS
CONTAINER_RUN · golang@1golang:1.26-alpine@sha256:28d89ee9cc0f…
2026-08-28

Fall

HOW
Ziel
verify pkg:golang/github.com/pkg/errors@v0.9.1
Pakete
Erstellt
2026-08-28T00:14:06Z

Contract

  1. errors.New and errors.Errorf create errors with stack trace capture and formatted messages
  2. errors.Wrap and errors.Wrapf annotate an error with context message and stack trace, returning nil for a nil error
  3. errors.WithMessage and errors.WithMessagef add context message without altering the cause, returning nil for a nil error
  4. errors.WithStack attaches stack trace information to an existing error without altering its message
  5. errors.Cause recursively unwraps nested wrapped errors to retrieve the root underlying cause
  6. Formatting wrapped errors with %+v outputs the full multi-frame stack trace

Dateien

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

Quellartefakt herunterladen (tar.gz)

Quelltext

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 pkg:golang/github.com/pkg/errors@v0.9.1
Kind: HOW

Use EXACTLY these public packages and versions:
  - pkg:golang/github.com/pkg/errors@v0.9.1
Constraints:
  - executionContext: node
Required runtime conditions:
  - ecosystem: npm
  - language: javascript
  - moduleSystem: cjs
  - packageManager: npm@10.9.8
  - runtime: node@22.23.2

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:ee9bf7dd4bfbaa2af1da9bfb6bf54b76eab2a11455a930614bb3bfa90008757f","contract":["errors.New and errors.Errorf create errors with stack trace capture and formatted messages","errors.Wrap and errors.Wrapf annotate an error with context message and stack trace, returning nil for a nil error","errors.WithMessage and errors.WithMessagef add context message without altering the cause, returning nil for a nil error","errors.WithStack attaches stack trace information to an existing error without altering its message","errors.Cause recursively unwraps nested wrapped errors to retrieve the root underlying cause","Formatting wrapped errors with %+v outputs the full multi-frame stack trace"],"goal":"verify pkg:golang/github.com/pkg/errors@v0.9.1","kind":"HOW","packages":["pkg:golang/github.com/pkg/errors@v0.9.1"],"schemaVersion":1},"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/github.com/pkg/errors@v0.9.1"],"schemaVersion":1,"subject":"pkg:golang/github.com/pkg/errors@v0.9.1","verifierAdapter":"golang@1"}
go.mod
module sample

go 1.26.6

require github.com/pkg/errors v0.9.1
go.sum
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
main.go
package main

import (
	"fmt"

	"github.com/pkg/errors"
)

func parseConfig(filename string) error {
	return errors.Errorf("file %q not found", filename)
}

func initializeService() error {
	err := parseConfig("config.json")
	if err != nil {
		return errors.Wrap(err, "failed to initialize service")
	}
	return nil
}

func main() {
	err := initializeService()
	if err != nil {
		fmt.Printf("Error: %v\n", err)
		fmt.Printf("Cause: %v\n", errors.Cause(err))
		fmt.Printf("Stack trace:\n%+v\n", err)
	}
}
spec.json
{
  "schemaVersion": 1,
  "goal": "verify pkg:golang/github.com/pkg/errors@v0.9.1",
  "kind": "HOW",
  "packages": [
    "pkg:golang/github.com/pkg/errors@v0.9.1"
  ],
  "constraints": {
    "executionContext": "node"
  },
  "runtimeConditions": {
    "ecosystem": "npm",
    "language": "javascript",
    "moduleSystem": "cjs",
    "packageManager": "npm@10.9.8",
    "runtime": "node@22.23.2"
  }
}
test/contract.go
package main

import (
	"fmt"
	"os"
	"strings"

	"github.com/pkg/errors"
)

func main() {
	if err := runContract(); err != nil {
		fmt.Fprintf(os.Stderr, "Contract verification failed: %v\n", err)
		os.Exit(1)
	}
	fmt.Println("All pkg/errors contract assertions passed successfully.")
}

func runContract() error {
	// 1. errors.New and errors.Errorf create errors with stack trace and formatting
	newErr := errors.New("base error message")
	if newErr == nil || newErr.Error() != "base error message" {
		return fmt.Errorf("errors.New failed, got: %v", newErr)
	}

	formattedErr := errors.Errorf("formatted error with code %d", 404)
	if formattedErr == nil || formattedErr.Error() != "formatted error with code 404" {
		return fmt.Errorf("errors.Errorf failed, got: %v", formattedErr)
	}

	formattedStackTrace := fmt.Sprintf("%+v", formattedErr)
	if !strings.Contains(formattedStackTrace, "contract.go") {
		return fmt.Errorf("expected stack trace from errors.Errorf to contain 'contract.go', got:\n%s", formattedStackTrace)
	}

	// 2. errors.Wrap and errors.Wrapf annotate error with context and stack trace, nil safety
	if errors.Wrap(nil, "ignored context") != nil {
		return fmt.Errorf("expected errors.Wrap(nil, ...) to return nil")
	}
	if errors.Wrapf(nil, "ignored %s", "context") != nil {
		return fmt.Errorf("expected errors.Wrapf(nil, ...) to return nil")
	}

	baseErr := errors.New("disk full")
	wrappedErr := errors.Wrap(baseErr, "write failed")
	if wrappedErr.Error() != "write failed: disk full" {
		return fmt.Errorf("expected 'write failed: disk full', got: %q", wrappedErr.Error())
	}

	wrappedFormattedErr := errors.Wrapf(baseErr, "write to device %s failed", "/dev/sda1")
	if wrappedFormattedErr.Error() != "write to device /dev/sda1 failed: disk full" {
		return fmt.Errorf("expected 'write to device /dev/sda1 failed: disk full', got: %q", wrappedFormattedErr.Error())
	}

	// 3. errors.WithMessage and errors.WithMessagef add context message without adding stack trace, nil safety
	if errors.WithMessage(nil, "ignored") != nil {
		return fmt.Errorf("expected errors.WithMessage(nil, ...) to return nil")
	}
	if errors.WithMessagef(nil, "ignored %d", 1) != nil {
		return fmt.Errorf("expected errors.WithMessagef(nil, ...) to return nil")
	}

	withMsgErr := errors.WithMessage(baseErr, "operation timeout")
	if withMsgErr.Error() != "operation timeout: disk full" {
		return fmt.Errorf("expected 'operation timeout: disk full', got: %q", withMsgErr.Error())
	}

	withMsgfErr := errors.WithMessagef(baseErr, "step %d failed", 2)
	if withMsgfErr.Error() != "step 2 failed: disk full" {
		return fmt.Errorf("expected 'step 2 failed: disk full', got: %q", withMsgfErr.Error())
	}

	// 4. errors.WithStack attaches stack trace without modifying message, nil safety
	if errors.WithStack(nil) != nil {
		return fmt.Errorf("expected errors.WithStack(nil) to return nil")
	}

	plainErr := fmt.Errorf("plain standard error")
	stackedErr := errors.WithStack(plainErr)
	if stackedErr.Error() != "plain standard error" {
		return fmt.Errorf("expected message preserved in WithStack, got: %q", stackedErr.Error())
	}
	stackedOutput := fmt.Sprintf("%+v", stackedErr)
	if !strings.Contains(stackedOutput, "contract.go") {
		return fmt.Errorf("expected WithStack output to include stack trace with contract.go, got:\n%s", stackedOutput)
	}

	// 5. errors.Cause recursively retrieves the root underlying error
	if errors.Cause(nil) != nil {
		return fmt.Errorf("expected errors.Cause(nil) to be nil")
	}

	rootErr := errors.New("root cause failure")
	layer1 := errors.WithMessage(rootErr, "layer 1")
	layer2 := errors.Wrap(layer1, "layer 2")
	layer3 := errors.WithStack(layer2)
	layer4 := errors.WithMessagef(layer3, "layer 4: attempt %d", 3)

	cause := errors.Cause(layer4)
	if cause != rootErr {
		return fmt.Errorf("expected Cause to return rootErr, got: %v", cause)
	}

	// 6. Formatting wrapped errors with %+v prints all layers and stack frames
	nestedOutput := fmt.Sprintf("%+v", layer2)
	if !strings.Contains(nestedOutput, "root cause failure") || !strings.Contains(nestedOutput, "layer 1") || !strings.Contains(nestedOutput, "layer 2") {
		return fmt.Errorf("expected %+v output to include all wrap messages, got:\n%s", nestedOutput)
	}

	return nil
}

Ursprungs-Seeder

anonym