Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

fix: avoid emitting version warning when connection error encountered#3082

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 ourterms of service andprivacy statement. We’ll occasionally send you account related emails.

Already on GitHub?Sign in to your account

Merged
sreya merged 2 commits intomainfromjon/fixcheckerrornoise
Jul 21, 2022
Merged
Show file tree
Hide file tree
Changes fromall 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
5 changes: 5 additions & 0 deletionscli/root.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -455,6 +455,11 @@ func checkVersions(cmd *cobra.Command, client *codersdk.Client) error {
clientVersion := buildinfo.Version()

info, err := client.BuildInfo(cmd.Context())
// Avoid printing errors that are connection-related.
if codersdk.IsConnectionErr(err) {
return nil
}

if err != nil {
return xerrors.Errorf("build info: %w", err)
}
Expand Down
19 changes: 19 additions & 0 deletionscodersdk/error.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,11 @@
package codersdk

import (
"net"

"golang.org/x/xerrors"
)

// Response represents a generic HTTP response.
type Response struct {
// Message is an actionable message that depicts actions the request took.
Expand All@@ -25,3 +31,16 @@ type ValidationError struct {
Field string `json:"field" validate:"required"`
Detail string `json:"detail" validate:"required"`
}

// IsConnectionErr is a convenience function for checking if the source of an
// error is due to a 'connection refused', 'no such host', etc.
func IsConnectionErr(err error) bool {
var (
// E.g. no such host
dnsErr *net.DNSError
// Eg. connection refused
opErr *net.OpError
)

return xerrors.As(err, &dnsErr) || xerrors.As(err, &opErr)
}
65 changes: 65 additions & 0 deletionscodersdk/error_test.go
View file
Open in desktop
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,65 @@
package codersdk_test

import (
"net"
"os"
"testing"

"github.com/stretchr/testify/require"
"golang.org/x/xerrors"

"github.com/coder/coder/codersdk"
)

func TestIsConnectionErr(t *testing.T) {
t.Parallel()

type tc = struct {
name string
err error
expectedResult bool
}

cases := []tc{
{
// E.g. "no such host"
name: "DNSError",
err: &net.DNSError{
Err: "no such host",
Name: "foofoo",
Server: "1.1.1.1:53",
IsTimeout: false,
IsTemporary: false,
IsNotFound: true,
},
expectedResult: true,
},
{
// E.g. "connection refused"
name: "OpErr",
err: &net.OpError{
Op: "dial",
Net: "tcp",
Source: nil,
Addr: nil,
Err: &os.SyscallError{},
},
expectedResult: true,
},
{
name: "OpaqueError",
err: xerrors.Errorf("I'm opaque!"),
expectedResult: false,
},
}

for _, c := range cases {
c := c

t.Run(c.name, func(t *testing.T) {
t.Parallel()

require.Equal(t, c.expectedResult, codersdk.IsConnectionErr(c.err))
})
}
}
4 changes: 2 additions & 2 deletionssite/src/api/typesGenerated.ts
View file
Open in desktop
Original file line numberDiff line numberDiff line change
Expand Up@@ -250,7 +250,7 @@ export interface PutExtendWorkspaceRequest {
readonly deadline: string
}

// From codersdk/error.go:4:6
// From codersdk/error.go:10:6
export interface Response {
readonly message: string
readonly detail?: string
Expand DownExpand Up@@ -386,7 +386,7 @@ export interface UsersRequest extends Pagination {
readonly q?: string
}

// From codersdk/error.go:24:6
// From codersdk/error.go:30:6
export interface ValidationError {
readonly field: string
readonly detail: string
Expand Down

[8]ページ先頭

©2009-2025 Movatter.jp