Skip to content
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
14 changes: 14 additions & 0 deletions internal/login/errors_test.go
Original file line number Diff line number Diff line change
@@ -0,0 +1,14 @@
package login

import (
"errors"
"fmt"
"testing"
)

func TestNoRemoteDebugEndpointIsWrappable(t *testing.T) {
wrapped := fmt.Errorf("firstAvailableRemoteDebugEndpoint: %w", errNoRemoteDebugEndpoint)
if !errors.Is(wrapped, errNoRemoteDebugEndpoint) {
t.Fatalf("errors.Is should report wrapped error as errNoRemoteDebugEndpoint, got false")
}
}
14 changes: 7 additions & 7 deletions internal/login/login.go
Original file line number Diff line number Diff line change
Expand Up @@ -222,7 +222,7 @@

if provider == session.ProviderDelio {
if !hasDelioAuthCookie(cookieHeader) {
return nil, fmt.Errorf("Delio auth cookies not detected — open a logged-in Delio page or sign in in the opened browser window and wait for the session to load")

Check failure on line 225 in internal/login/login.go

View workflow job for this annotation

GitHub Actions / lint

ST1005: error strings should not be capitalized (staticcheck)
}
} else if accessToken == "" {
return nil, fmt.Errorf("Frisco access token not detected — open a logged-in Frisco page or sign in and navigate to cart/account to trigger API requests")
Expand Down Expand Up @@ -496,13 +496,13 @@

func copyBrowserProfileSnapshot(srcUserData, dstUserData, profileDirectory string) error {
if err := os.MkdirAll(dstUserData, 0o700); err != nil {
return err
return fmt.Errorf("create snapshot user data dir: %w", err)
}
localStateSrc := filepath.Join(srcUserData, "Local State")
localStateDst := filepath.Join(dstUserData, "Local State")
if _, err := os.Stat(localStateSrc); err == nil {
if err := copyFile(localStateSrc, localStateDst); err != nil {
return err
return fmt.Errorf("copy browser Local State: %w", err)
}
}
srcProfile := filepath.Join(srcUserData, profileDirectory)
Expand Down Expand Up @@ -557,23 +557,23 @@
func copyFile(src, dst string) error {
in, err := os.Open(src)
if err != nil {
return err
return fmt.Errorf("open source file %s: %w", src, err)
}
defer func() { _ = in.Close() }()
info, err := in.Stat()
if err != nil {
return err
return fmt.Errorf("stat source file %s: %w", src, err)
}
if err := os.MkdirAll(filepath.Dir(dst), 0o700); err != nil {
return err
return fmt.Errorf("create destination dir for %s: %w", dst, err)
}
out, err := os.OpenFile(dst, os.O_CREATE|os.O_WRONLY|os.O_TRUNC, info.Mode())
if err != nil {
return err
return fmt.Errorf("create destination file %s: %w", dst, err)
}
defer func() { _ = out.Close() }()
if _, err := io.Copy(out, in); err != nil {
return err
return fmt.Errorf("copy file contents to %s: %w", dst, err)
}
return out.Chmod(info.Mode())
}
Expand Down
2 changes: 1 addition & 1 deletion internal/login/remote_debug.go
Original file line number Diff line number Diff line change
Expand Up @@ -21,25 +21,25 @@
"github.com/wydrox/martmart-cli/internal/session"
)

type remoteDebugVersion struct {

Check failure on line 24 in internal/login/remote_debug.go

View workflow job for this annotation

GitHub Actions / lint

type remoteDebugVersion is unused (unused)
Browser string `json:"Browser"`
WebSocketDebuggerURL string `json:"webSocketDebuggerUrl"`
}

type remoteDebugTarget struct {

Check failure on line 29 in internal/login/remote_debug.go

View workflow job for this annotation

GitHub Actions / lint

type remoteDebugTarget is unused (unused)
ID string `json:"id"`
Type string `json:"type"`
URL string `json:"url"`
Title string `json:"title"`
}

type remoteDebugDelioCapture struct {

Check failure on line 36 in internal/login/remote_debug.go

View workflow job for this annotation

GitHub Actions / lint

type remoteDebugDelioCapture is unused (unused)
Headers map[string]string
CookieHeader string
UserID string
}

type remoteDebugFriscoCapture struct {

Check failure on line 42 in internal/login/remote_debug.go

View workflow job for this annotation

GitHub Actions / lint

type remoteDebugFriscoCapture is unused (unused)
CookieHeader string
AccessToken string
RefreshToken string
Expand Down Expand Up @@ -216,7 +216,7 @@
client := &http.Client{Timeout: 2 * time.Second}
resp, err := client.Get(rawURL)
if err != nil {
return err
return fmt.Errorf("GET %s: %w", rawURL, err)
}
defer func() { _ = resp.Body.Close() }()
if resp.StatusCode < 200 || resp.StatusCode >= 300 {
Expand Down
Loading