Skip to content

Commit

Permalink
on error, report which cassette was not found
Browse files Browse the repository at this point in the history
Before:

  requested cassette not found

After:

  requested cassette not found: FILENAME

There is a caveat: this change tries to be as backwards compatible as possible,
but, as the change in recorder_test.go shows, it breaks direct (!=) comparison
with the sentinel error. On the other hand, one could argue that sentinel
errors should always be compared with errors.Is().

In case you are not comfortable accepting this PR, no problems!

Thanks for go-vcr, everybody I show it to starts using it :-)
  • Loading branch information
marco-m authored and dnaeon committed Feb 26, 2024
1 parent 6757a75 commit 89d872b
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 2 deletions.
3 changes: 2 additions & 1 deletion recorder/recorder.go
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@ import (
"bufio"
"bytes"
"errors"
"fmt"
"io"
"net/http"
"net/http/httputil"
Expand Down Expand Up @@ -210,7 +211,7 @@ func NewWithOptions(opts *Options) (*Recorder, error) {
rec.cassette = c
return rec, nil
case opts.Mode == ModeReplayOnly && !cassetteExists:
return nil, cassette.ErrCassetteNotFound
return nil, fmt.Errorf("%w: %s", cassette.ErrCassetteNotFound, cassetteFile)
case opts.Mode == ModeReplayOnly && cassetteExists:
c, err := cassette.Load(opts.CassetteName)
if err != nil {
Expand Down
3 changes: 2 additions & 1 deletion recorder/recorder_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -28,6 +28,7 @@ package recorder_test
import (
"bytes"
"context"
"errors"
"fmt"
"io"
"net/http"
Expand Down Expand Up @@ -238,7 +239,7 @@ func TestReplayOnlyModeFailsWithMissingCassette(t *testing.T) {
Mode: recorder.ModeReplayOnly,
}
_, err := recorder.NewWithOptions(opts)
if err != cassette.ErrCassetteNotFound {
if !errors.Is(err, cassette.ErrCassetteNotFound) {
t.Fatalf("expected cassette.ErrCassetteNotFound, got %v", err)
}
}
Expand Down

0 comments on commit 89d872b

Please sign in to comment.