pax_global_header00006660000000000000000000000064147673566410014535gustar00rootroot0000000000000052 comment=111a4dd9221e2425f80c1aed2eb75a98e542ffea wrap-1.2.2/000077500000000000000000000000001476735664100125105ustar00rootroot00000000000000wrap-1.2.2/.github/000077500000000000000000000000001476735664100140505ustar00rootroot00000000000000wrap-1.2.2/.github/dependabot.yml000066400000000000000000000004261476735664100167020ustar00rootroot00000000000000version: 2 updates: - package-ecosystem: gomod directory: "/" schedule: interval: daily open-pull-requests-limit: 10 allow: - dependency-type: "all" - package-ecosystem: github-actions directory: / schedule: interval: weekly open-pull-requests-limit: 10 wrap-1.2.2/.github/workflows/000077500000000000000000000000001476735664100161055ustar00rootroot00000000000000wrap-1.2.2/.github/workflows/auto-merge.yml000066400000000000000000000011751476735664100207010ustar00rootroot00000000000000--- name: Dependabot auto-merge on: pull_request permissions: contents: write pull-requests: write jobs: dependabot: runs-on: ubuntu-latest if: ${{ github.actor == 'dependabot[bot]' }} steps: - name: Dependabot metadata id: metadata uses: dependabot/fetch-metadata@v2.3.0 with: github-token: "${{ secrets.GITHUB_TOKEN }}" - name: Enable auto-merge for Dependabot PRs env: PR_URL: ${{github.event.pull_request.html_url}} GITHUB_TOKEN: ${{secrets.GITHUB_TOKEN}} run: | gh pr review --approve "$PR_URL" gh pr merge --auto --merge "$PR_URL" wrap-1.2.2/.github/workflows/golangci-lint.yml000066400000000000000000000010011476735664100213470ustar00rootroot00000000000000--- name: golangci-lint on: push: tags-ignore: - '**' branches: - main pull_request: branches: - main jobs: golangci-lint: name: golangci-lint runs-on: ubuntu-latest steps: - name: Set up Go uses: actions/setup-go@v5 with: go-version: stable - name: Check out code into the Go module directory uses: actions/checkout@v4 - name: golangci-lint uses: golangci/golangci-lint-action@v6 with: only-new-issues: true wrap-1.2.2/.github/workflows/tests.yml000066400000000000000000000020651476735664100177750ustar00rootroot00000000000000--- name: Tests on: push: tags-ignore: - '**' branches: - main pull_request: branches: - main jobs: build: name: Tests runs-on: ubuntu-latest steps: - name: Set up Go uses: actions/setup-go@v5 with: go-version: stable - name: Check out code into the Go module directory uses: actions/checkout@v4 - name: Build Go Code run: | go build ./... - name: Run Go Unit Tests run: | go install -mod=mod github.com/onsi/ginkgo/v2/ginkgo ginkgo run \ --coverprofile=unit.coverprofile \ --randomize-all \ --randomize-suites \ --fail-on-pending \ --keep-going \ --compilers=2 \ --race \ --trace \ ./... - name: Upload Code Coverage Profile uses: codecov/codecov-action@v5 env: CODECOV_TOKEN: ${{ secrets.CODECOV_TOKEN }} with: files: unit.coverprofile flags: unittests fail_ci_if_error: true verbose: false wrap-1.2.2/.gitignore000066400000000000000000000000171476735664100144760ustar00rootroot00000000000000*.coverprofile wrap-1.2.2/LICENSE000066400000000000000000000020621476735664100135150ustar00rootroot00000000000000MIT License Copyright (c) 2019 The Homeport Team Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions: The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software. THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. wrap-1.2.2/README.md000066400000000000000000000016461476735664100137760ustar00rootroot00000000000000# wrap [![License](https://img.shields.io/github/license/gonvenience/wrap.svg)](https://github.com/gonvenience/wrap/blob/main/LICENSE) [![Go Report Card](https://goreportcard.com/badge/github.com/gonvenience/wrap)](https://goreportcard.com/report/github.com/gonvenience/wrap) [![Tests](https://github.com/gonvenience/wrap/workflows/Tests/badge.svg)](https://github.com/gonvenience/wrap/actions?query=workflow%3A%22Tests%22) [![Codecov](https://img.shields.io/codecov/c/github/gonvenience/wrap/main.svg)](https://codecov.io/gh/gonvenience/wrap) [![PkgGoDev](https://pkg.go.dev/badge/github.com/gonvenience/wrap)](https://pkg.go.dev/github.com/gonvenience/wrap) [![Release](https://img.shields.io/github/release/gonvenience/wrap.svg)](https://github.com/gonvenience/wrap/releases/latest) ![GitHub go.mod Go version](https://img.shields.io/github/go-mod/go-version/gonvenience/wrap) Golang package to wrap things into a bit of context wrap-1.2.2/error.go000066400000000000000000000054061476735664100141750ustar00rootroot00000000000000// Copyright © 2019 The Homeport Team // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. package wrap import ( "errors" "fmt" ) // ContextError interface describes the simple type that is able to provide a // textual context as well as the cause explaining the underlying error. // // Deprecated: Discontinued, use fmt.Errorf() instead. type ContextError interface { Context() string Cause() error } // ListOfErrors interface describes a list of errors with additional context // information with an explanation. // // Deprecated: Discontinued, use errors.Join() instead. type ListOfErrors interface { Context() string Errors() []error } // Error creates an error with additional context // // Deprecated: Use fmt.Errorf() instead using the `%w` format specifier. func Error(err error, context string) error { if err == nil { return errors.New(context) } return fmt.Errorf("%s: %w", context, err) } // Errorf creates an error with additional formatted context // // Deprecated: Use fmt.Errorf() instead using the `%w` format specifier. func Errorf(err error, format string, a ...interface{}) error { return Error(err, fmt.Sprintf(format, a...)) } // Errors creates a list of errors with additional context // // Deprecated: Use fmt.Errorf() and errors.Join() instead. func Errors(errs []error, context string) error { switch len(errs) { case 0: return errors.New(context) case 1: return fmt.Errorf("%s: %w", context, errs[0]) default: return fmt.Errorf("%s:\n%w", context, errors.Join(errs...), ) } } // Errorsf creates a list of errors with additional formatted context // // Deprecated: Use fmt.Errorf() and errors.Join() instead. func Errorsf(errors []error, format string, a ...interface{}) error { return Errors(errors, fmt.Sprintf(format, a...)) } wrap-1.2.2/error_test.go000066400000000000000000000064061476735664100152350ustar00rootroot00000000000000// Copyright © 2019 The Homeport Team // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. package wrap_test import ( "fmt" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" . "github.com/gonvenience/wrap" ) var _ = Describe("wrap package tests", func() { var exampleErr = fmt.Errorf("failed to do x, because of y") Context("wrapping errors in context", func() { var err = Error( exampleErr, "issue setting up z", ) It("should behave and render like a standard error", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("issue setting up z: failed to do x, because of y")) }) It("should fall back to a simple error if no cause is provided", func() { err := Error(nil, "failed to do thing A") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("failed to do thing A")) }) }) Context("wrapping multiple errors with context", func() { var ( err = Errorsf( []error{ fmt.Errorf("issue setting up x"), fmt.Errorf("issue setting up y"), fmt.Errorf("issue setting up z"), }, "failed to setup component %s", "A", ) ) It("should behave and render like a standard error", func() { Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("failed to setup component A:\nissue setting up x\nissue setting up y\nissue setting up z")) }) It("should fall back to a simple error if no cause is provided", func() { err := Errors(nil, "failed to do thing A") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("failed to do thing A")) }) It("should render like a simple wrapped error if there is only one error list entry", func() { err := Errorsf( []error{fmt.Errorf("issue setting up x")}, "failed to setup component %s", "A", ) Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("failed to setup component A: issue setting up x")) }) }) Context("projects using wrap package", func() { It("should be possible to use an error to wrap with context", func() { err := Errorf(exampleErr, "unable to set up %s and %s", "A", "B") Expect(err).To(HaveOccurred()) Expect(err.Error()).To(BeEquivalentTo("unable to set up A and B: failed to do x, because of y")) }) }) }) wrap-1.2.2/go.mod000066400000000000000000000010411476735664100136120ustar00rootroot00000000000000module github.com/gonvenience/wrap go 1.23.0 require ( github.com/onsi/ginkgo/v2 v2.23.3 github.com/onsi/gomega v1.36.3 ) require ( github.com/go-logr/logr v1.4.2 // indirect github.com/go-task/slim-sprig/v3 v3.0.0 // indirect github.com/google/go-cmp v0.7.0 // indirect github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad // indirect golang.org/x/net v0.37.0 // indirect golang.org/x/sys v0.31.0 // indirect golang.org/x/text v0.23.0 // indirect golang.org/x/tools v0.31.0 // indirect gopkg.in/yaml.v3 v3.0.1 // indirect ) wrap-1.2.2/go.sum000066400000000000000000000052701476735664100136470ustar00rootroot00000000000000github.com/davecgh/go-spew v1.1.1 h1:vj9j/u1bqnvCEfJOwUhtlOARqs3+rkHYY13jYWTU97c= github.com/davecgh/go-spew v1.1.1/go.mod h1:J7Y8YcW2NihsgmVo/mv3lAwl/skON4iLHjSsI+c5H38= github.com/go-logr/logr v1.4.2 h1:6pFjapn8bFcIbiKo3XT4j/BhANplGihG6tvd+8rYgrY= github.com/go-logr/logr v1.4.2/go.mod h1:9T104GzyrTigFIr8wt5mBrctHMim0Nb2HLGrmQ40KvY= github.com/go-task/slim-sprig/v3 v3.0.0 h1:sUs3vkvUymDpBKi3qH1YSqBQk9+9D/8M2mN1vB6EwHI= github.com/go-task/slim-sprig/v3 v3.0.0/go.mod h1:W848ghGpv3Qj3dhTPRyJypKRiqCdHZiAzKg9hl15HA8= github.com/google/go-cmp v0.7.0 h1:wk8382ETsv4JYUZwIsn6YpYiWiBsYLSJiTsyBybVuN8= github.com/google/go-cmp v0.7.0/go.mod h1:pXiqmnSA92OHEEa9HXL2W4E7lf9JzCmGVUdgjX3N/iU= github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad h1:a6HEuzUHeKH6hwfN/ZoQgRgVIWFJljSWa/zetS2WTvg= github.com/google/pprof v0.0.0-20241210010833-40e02aabc2ad/go.mod h1:vavhavw2zAxS5dIdcRluK6cSGGPlZynqzFM8NdvU144= github.com/onsi/ginkgo/v2 v2.23.3 h1:edHxnszytJ4lD9D5Jjc4tiDkPBZ3siDeJJkUZJJVkp0= github.com/onsi/ginkgo/v2 v2.23.3/go.mod h1:zXTP6xIp3U8aVuXN8ENK9IXRaTjFnpVB9mGmaSRvxnM= github.com/onsi/gomega v1.36.3 h1:hID7cr8t3Wp26+cYnfcjR6HpJ00fdogN6dqZ1t6IylU= github.com/onsi/gomega v1.36.3/go.mod h1:8D9+Txp43QWKhM24yyOBEdpkzN8FvJyAwecBgsU4KU0= github.com/pmezard/go-difflib v1.0.0 h1:4DBwDE0NGyQoBHbLQYPwSUPoCMWR5BEzIk/f1lZbAQM= github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4= github.com/stretchr/testify v1.8.4 h1:CcVxjf3Q8PM0mHUKJCdn+eZZtm5yQwehR5yeSVQQcUk= github.com/stretchr/testify v1.8.4/go.mod h1:sz/lmYIOXD/1dqDmKjjqLyZ2RngseejIcXlSw2iwfAo= golang.org/x/net v0.37.0 h1:1zLorHbz+LYj7MQlSf1+2tPIIgibq2eL5xkrGk6f+2c= golang.org/x/net v0.37.0/go.mod h1:ivrbrMbzFq5J41QOQh0siUuly180yBYtLp+CKbEaFx8= golang.org/x/sys v0.31.0 h1:ioabZlmFYtWhL+TRYpcnNlLwhyxaM9kWTDEmfnprqik= golang.org/x/sys v0.31.0/go.mod h1:BJP2sWEmIv4KK5OTEluFJCKSidICx8ciO85XgH3Ak8k= golang.org/x/text v0.23.0 h1:D71I7dUrlY+VX0gQShAThNGHFxZ13dGLBHQLVl1mJlY= golang.org/x/text v0.23.0/go.mod h1:/BLNzu4aZCJ1+kcD0DNRotWKage4q2rGVAg4o22unh4= golang.org/x/tools v0.31.0 h1:0EedkvKDbh+qistFTd0Bcwe/YLh4vHwWEkiI0toFIBU= golang.org/x/tools v0.31.0/go.mod h1:naFTU+Cev749tSJRXJlna0T3WxKvb1kWEx15xA4SdmQ= google.golang.org/protobuf v1.36.5 h1:tPhr+woSbjfYvY6/GPufUoYizxw1cF/yFoxJ2fmpwlM= google.golang.org/protobuf v1.36.5/go.mod h1:9fA7Ob0pmnwhb644+1+CVWFRbNajQ6iRojtC/QF5bRE= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405 h1:yhCVgyC4o1eVCa2tZl7eS0r+SDo693bJlVdllGtEeKM= gopkg.in/check.v1 v0.0.0-20161208181325-20d25e280405/go.mod h1:Co6ibVJAznAaIkqp8huTwlJQCZ016jof/cbN4VW5Yz0= gopkg.in/yaml.v3 v3.0.1 h1:fxVm/GzAzEWqLHuvctI91KS9hhNmmWOoWu0XTYJS7CA= gopkg.in/yaml.v3 v3.0.1/go.mod h1:K4uyk7z7BCEPqu6E+C64Yfv1cQ7kz7rIZviUmN+EgEM= wrap-1.2.2/wrap.go000066400000000000000000000022661476735664100140160ustar00rootroot00000000000000// Copyright © 2019 The Homeport Team // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. /* Package wrap contains code to simply wrap things into a bit of context. */ package wrap wrap-1.2.2/wrap_suite_test.go000066400000000000000000000024271476735664100162650ustar00rootroot00000000000000// Copyright © 2019 The Homeport Team // // Permission is hereby granted, free of charge, to any person obtaining a copy // of this software and associated documentation files (the "Software"), to deal // in the Software without restriction, including without limitation the rights // to use, copy, modify, merge, publish, distribute, sublicense, and/or sell // copies of the Software, and to permit persons to whom the Software is // furnished to do so, subject to the following conditions: // // The above copyright notice and this permission notice shall be included in // all copies or substantial portions of the Software. // // THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR // IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, // FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE // AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER // LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, // OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN // THE SOFTWARE. package wrap_test import ( "testing" . "github.com/onsi/ginkgo/v2" . "github.com/onsi/gomega" ) func TestWrap(t *testing.T) { RegisterFailHandler(Fail) RunSpecs(t, "wrap suite") }