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

chore: handle errors in wsproxy server for cli using buildinfo#11584

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
Emyrk merged 11 commits intomainfromstevenmasley/wsproxy_errors
Jan 11, 2024

Conversation

Emyrk
Copy link
Member

@EmyrkEmyrk commentedJan 11, 2024
edited
Loading

See for yourself. I don't think encoding this into a static unit test would be very helpful. It would just cost more time to fix when you change things. Maybe a golden-file type test would be appropriate here at some point.

go run main.go exp example-error apigo run main.go exp example-error cmdgo run main.go exp example-error multi-errorgo run main.go exp example-error validation

Before

Coder Workspace Proxy v0.0.0-devel - Your Self-Hosted Remote Development PlatformStarted HTTP listener at http://127.0.0.1:3000View the Web UI: http://136.49.34.247:9344Encountered an error running "coder workspace-proxy server"create workspace proxy: failed to fetch build info from "https://filebrowser--dev--coder--emyrk--apps.dev.coder.com/": invalid character '<' looking for beginning of valueexit status 1

After

We have to show the html because we have no clue what the response body is. This error is not perfect, but it is a lot better.

Coder Workspace Proxy v0.0.0-devel - Your Self-Hosted Remote Development PlatformStarted HTTP listener at http://127.0.0.1:3000View the Web UI: http://136.49.34.247:9344Encountered an error running "coder workspace-proxy server"2 errors encountered:1.  unable to fetch build info from primary coderd. Are you sure "https://filebrowser--dev--coder--emyrk--apps.dev.coder.com/" is a coderd instance?2.  unexpected non-JSON response "text/html; charset=utf-8"    <!doctype html>        <!--        ▄█▀    ▀█▄         ▄▄ ▀▀▀  █▌   ██▀▀█▄          ▐█     ▄▄██▀▀█▄▄▄  ██  ██      █▀▀█ ▐█▀▀██ ▄█▀▀█ █▀▀    █▌   ▄▌   ▐█ █▌  ▀█▄▄▄█▌ █  █ ▐█  ██ ██▀▀  █         ██████▀▄█    ▀▀▀▀   ▀▀▀▀  ▀▀▀▀▀  ▀▀▀▀ ▀      -->        <head>      <meta charset="utf-8" />      <title>Coder</title>      <meta name="viewport" content="width=device-width, initial-scale=1" />      <meta name="theme-color" content="#17172E" />      <meta name="application-name" content="Coder" />      <meta property="og:type" content="website" />      <meta property="csrf-token" content="8bkWpep/Yq0LhtA3Viok+2hrQ2vqhG+znnp88OSR3Q8LD/wfVJG00NPh8WEL5yVgkmbadKGwB0p6xXGtnX76Bw==" />      <meta property="build-info" content="{&#34;external_url&#34;:&#34;https://github.com/coder/coder/commit/5b122d108e101219e21a05229c5959108b359e78&#34;,&#34;version&#34;:&#34;v2.6.0-devel+5b122d108&#34;,&#34;dashboard_url&#34;:&#34;&#34;,&#34;workspace_proxy&#34;:false,&#34;agent_api_version&#34;:&#34;&#34;}" />      <meta property="user" content="" />      <meta property="entitlements" content="" />      <meta property="appearance" content="" />      <meta property="experiments" content="" />      <meta property="regions" content="" />      <meta property="docs-url" content="" />      <meta property="logo-url" content="" />      <!-- We need to set data-react-helmet to be able to override it in the workspace page -->      <link        rel="alternate icon"        type="image/png"        href="/favicons/favicon-light.png"        media="(prefers-color-scheme: dark)"        data-react-helmet="true"      />      <link        rel="icon"        type="image/svg+xml"        href="/favicons/favicon-light.svg"        media="(prefers-color-scheme: dark)"        data-react-helmet="true"      />      <link        rel="alternate icon"        type="image/png"        href="/favicons/favicon-dark.png"        media="(prefers-color-scheme: light)"        data-react-helmet="true"      />      <link...exit status 1

@EmyrkEmyrk changed the titlechore: Error handling for wsproxy server using buildinfochore: cli error handling for wsproxy server using buildinfoJan 11, 2024
Comment on lines +1182 to +1196
// traceError is a helper function that aides developers debugging failed cli
// commands. When we pretty print errors, we lose the context in which they came.
// This function adds the context back. Unfortunately there is no easy way to get
// the prefix to: "error string: %w", so we do a bit of string manipulation.
//
//nolint:errorlint
func traceError(err error) string {
if uw, ok := err.(interface{ Unwrap() error }); ok {
a, b := err.Error(), uw.Unwrap().Error()
c := strings.TrimSuffix(a, b)
return c
}
return err.Error()
}

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

This is the biggest thing I added, and it only prints inverbose mode.

Essentially when we wrap some errors, we lose the context because the pretty printer doesn't know what to do with them.

An example is:

return fmt.Errorf("fetch buildinfo: %w", err)

The underlyingerr is an SDK error, so the contextfetch buildinfo: is lost.
This code aims to put that back in somewhere that is reasonable, so if you run-v in your command, that info returns.


I am debating just always printing this, because I can't image it gets too unwieldly.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I decided to always print this. Without it, it is really hard to debug where some api calls fail.

@EmyrkEmyrk changed the titlechore: cli error handling for wsproxy server using buildinfochore: handle errors in wsproxy server for cli using buildinfoJan 11, 2024
@EmyrkEmyrk requested a review fromsreyaJanuary 11, 2024 22:29
Copy link
Collaborator

@sreyasreya left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

I kinda followed it, having more detailed errors is always a win. Is it not possible to have some sort of golden file or templated string that we can compare against so that someone doesn't unintentionally mess up the formatting?

@@ -65,14 +70,28 @@ func (RootCmd) errorExample() *clibase.Cmd {
// A multi-error
{
Use: "multi-error",
Handler: func(inv *clibase.Invocation) error {
Copy link
Collaborator

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

should we hide this command? There's no reason a user would ever need to use this.

Copy link
MemberAuthor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others.Learn more.

It is hidden up the stack:

Hidden:true,

@EmyrkGraphite App
Copy link
MemberAuthor

In this stack:🔧 Improve error handling in wsproxy for primary proxyurl

This stack of pull requests is managed by Graphite.Learn more about stacking.

Join@Emyrk and the rest of your teammates onGraphiteGraphite

@Emyrk
Copy link
MemberAuthor

Is it not possible to have some sort of golden file or templated string that we can compare against so that someone doesn't unintentionally mess up the formatting?

We can. We can make it a followup PR. I don't have the bandwidth atm to add that

@EmyrkEmyrk merged commitf5a9f5c intomainJan 11, 2024
@EmyrkEmyrk deleted the stevenmasley/wsproxy_errors branchJanuary 11, 2024 22:55
@github-actionsgithub-actionsbot locked and limited conversation to collaboratorsJan 11, 2024
@sreya
Copy link
Collaborator

@Emyrk could you open an issue so that we can track and not forget?

@Emyrk
Copy link
MemberAuthor

@sreya#11588

Sign up for freeto subscribe to this conversation on GitHub. Already have an account?Sign in.
Reviewers

@sreyasreyasreya approved these changes

Assignees

@EmyrkEmyrk

Labels
None yet
Projects
None yet
Milestone
No milestone
Development

Successfully merging this pull request may close these issues.

2 participants
@Emyrk@sreya

[8]ページ先頭

©2009-2025 Movatter.jp