Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

feat: add support for some more errors (syscall errors and DNS specifically) #114

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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 @@
"io"
"net"
"net/http"
"os"

"github.com/pkg/errors"

Expand Down Expand Up @@ -73,7 +74,7 @@
errMsg = *trk.ErrMsg
}

if errType == "*net.OpError" {

Check warning on line 77 in cassette/track/track.go

View workflow job for this annotation

GitHub Actions / Linting

ifElseChain: rewrite if-else to switch statement (gocritic)
return &net.OpError{
Op: "govcr",
Net: "govcr",
Expand All @@ -81,6 +82,21 @@
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
Loading