Skip to content

Commit

Permalink
feat: add support for some more errors
Browse files Browse the repository at this point in the history
  • Loading branch information
dpittner committed Nov 25, 2024
1 parent ecffe9c commit 202158d
Show file tree
Hide file tree
Showing 2 changed files with 55 additions and 30 deletions.
69 changes: 39 additions & 30 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -41,35 +41,44 @@ This project is an adaptation for Google's Go / Golang programming language.

## Table of content

- [Simple VCR example](#simple-vcr-example)
- [Install](#install)
- [Glossary of Terms](#glossary-of-terms)
- [Concepts](#concepts)
- [VCRSettings](#vcrsettings)
- [Match a request to a cassette track](#match-a-request-to-a-cassette-track)
- [Track mutators](#track-mutators)
- [Cassette encryption](#cassette-encryption)
- [Cookbook](#cookbook)
- [Run the examples](#run-the-examples)
- [Recipe: VCR with custom `http.Client`](#recipe-vcr-with-custom-httpclient)
- [Recipe: Remove Response TLS](#recipe-remove-response-tls)
- [Recipe: Change the playback mode of the VCR](#recipe-change-the-playback-mode-of-the-vcr)
- [Recipe: VCR with encrypted cassette](#recipe-vcr-with-encrypted-cassette)
- [Recipe: VCR with encrypted cassette - custom nonce generator](#recipe-vcr-with-encrypted-cassette---custom-nonce-generator)
- [Recipe: Cassette decryption](#recipe-cassette-decryption)
- [Recipe: Changing cassette encryption](#recipe-changing-cassette-encryption)
- [Recipe: VCR with cassette storage on AWS S3](#recipe-vcr-with-cassette-storage-on-aws-s3)
- [Recipe: VCR with a custom RequestMatcher](#recipe-vcr-with-a-custom-requestmatcher)
- [Recipe: VCR with a replaying Track Mutator](#recipe-vcr-with-a-replaying-track-mutator)
- [Recipe: VCR with a recording Track Mutator](#recipe-vcr-with-a-recording-track-mutator)
- [More](#more)
- [Stats](#stats)
- [Run the tests](#run-the-tests)
- [Bugs](#bugs)
- [Improvements](#improvements)
- [Limitations](#limitations)
- [Contribute](#contribute)
- [Community Support Appeal](#community-support-appeal)
- [govcr](#govcr)
- [Table of content](#table-of-content)
- [Simple VCR example](#simple-vcr-example)
- [Install](#install)
- [Glossary of Terms](#glossary-of-terms)
- [Concepts](#concepts)
- [VCRSettings](#vcrsettings)
- [Match a request to a cassette track](#match-a-request-to-a-cassette-track)
- [Track mutators](#track-mutators)
- [Cassette encryption](#cassette-encryption)
- [Cookbook](#cookbook)
- [Run the examples](#run-the-examples)
- [Recipe: VCR with custom `http.Client`](#recipe-vcr-with-custom-httpclient)
- [Recipe: Remove Response TLS](#recipe-remove-response-tls)
- [Recipe: Change the playback mode of the VCR](#recipe-change-the-playback-mode-of-the-vcr)
- [Normal HTTP mode](#normal-http-mode)
- [Live only HTTP mode](#live-only-http-mode)
- [Read only cassette mode](#read-only-cassette-mode)
- [Offline HTTP mode](#offline-http-mode)
- [Recipe: VCR with encrypted cassette](#recipe-vcr-with-encrypted-cassette)
- [Recipe: VCR with encrypted cassette - custom nonce generator](#recipe-vcr-with-encrypted-cassette---custom-nonce-generator)
- [Recipe: Cassette decryption](#recipe-cassette-decryption)
- [Recipe: Changing cassette encryption](#recipe-changing-cassette-encryption)
- [Recipe: VCR with cassette storage on AWS S3](#recipe-vcr-with-cassette-storage-on-aws-s3)
- [Recipe: VCR with a custom RequestMatcher](#recipe-vcr-with-a-custom-requestmatcher)
- [Recipe: VCR with a replaying Track Mutator](#recipe-vcr-with-a-replaying-track-mutator)
- [Recipe: VCR with a recording Track Mutator](#recipe-vcr-with-a-recording-track-mutator)
- [More](#more)
- [Stats](#stats)
- [Run the tests](#run-the-tests)
- [Bugs](#bugs)
- [Improvements](#improvements)
- [Limitations](#limitations)
- [Go empty interfaces (`interface{}` / `any`)](#go-empty-interfaces-interface--any)
- [Support for multiple values in HTTP headers](#support-for-multiple-values-in-http-headers)
- [HTTP transport errors](#http-transport-errors)
- [Contribute](#contribute)
- [Community Support Appeal](#community-support-appeal)

## Simple VCR example

Expand Down Expand Up @@ -626,7 +635,7 @@ Objects cannot be created by name at runtime in Go. Rather than re-create the or

In practice, the implications for you depend on how much you care about the error type. If all you need to know is that an error occurred, you won't mind this limitation.

Mitigation: Support for common errors (network down) has been implemented. Support for more error types can be implemented, if there is appetite for it.
Mitigation: Support for common errors (network down, dns failure, timeout) has been implemented. Support for more error types can be implemented, if there is appetite for it.

[(toc)](#table-of-content)

Expand Down
16 changes: 16 additions & 0 deletions cassette/track/track.go
Original file line number Diff line number Diff line change
Expand Up @@ -6,6 +6,7 @@ import (
"io"
"net"
"net/http"
"os"

"github.com/pkg/errors"

Expand Down Expand Up @@ -81,6 +82,21 @@ func (trk *Track) ToErr() error {
Addr: nil,
Err: errors.WithStack(trkerr.NewErrTransportFailure(errType, errMsg)),
}
} else if errType == "*os.SyscallError" {
return &os.SyscallError{
Syscall: errMsg,
Err: errors.WithStack(trkerr.NewErrTransportFailure(errType, errMsg)),
}
} else if errType == "*net.DNSError" {
return &net.DNSError{
UnwrapErr: errors.WithStack(trkerr.NewErrTransportFailure(errType, errMsg)),
Err: errMsg,
Name: "govcr",
Server: "govcr",
IsTimeout: false,
IsTemporary: false,
IsNotFound: false,
}
}

return errors.WithStack(trkerr.NewErrTransportFailure(errType, errMsg))
Expand Down

0 comments on commit 202158d

Please sign in to comment.