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

service/dap: fix error string format #2549

Merged
merged 3 commits into from
Jun 23, 2021
Merged
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
6 changes: 3 additions & 3 deletions service/dap/server.go
Original file line number Diff line number Diff line change
Expand Up @@ -1072,7 +1072,7 @@ func (s *Server) onSetBreakpointsRequest(request *dap.SetBreakpointsRequest) {
continue
}
if _, ok := bpAdded[reqString]; ok {
err = fmt.Errorf("Breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column)
err = fmt.Errorf("breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column)
} else {
got.Cond = want.Condition
got.HitCond = want.HitCondition
Expand All @@ -1099,7 +1099,7 @@ func (s *Server) onSetBreakpointsRequest(request *dap.SetBreakpointsRequest) {
var got *api.Breakpoint
var err error
if _, ok := bpAdded[reqString]; ok {
err = fmt.Errorf("Breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column)
err = fmt.Errorf("breakpoint exists at %q, line: %d, column: %d", request.Arguments.Source.Path, want.Line, want.Column)
} else {
// Create new breakpoints.
got, err = s.debugger.CreateBreakpoint(
Expand Down Expand Up @@ -1167,7 +1167,7 @@ func (s *Server) onSetFunctionBreakpointsRequest(request *dap.SetFunctionBreakpo
continue
}
if _, ok := bpAdded[reqString]; ok {
err = fmt.Errorf("Breakpoint exists at function %q", want.Name)
err = fmt.Errorf("breakpoint exists at function %q", want.Name)
} else {
got.Cond = want.Condition
got.HitCond = want.HitCondition
Expand Down
16 changes: 10 additions & 6 deletions service/dap/server_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -1947,7 +1947,7 @@ func checkBreakpoints(t *testing.T, client *daptest.Client, bps []Breakpoint, br
}
for i, bp := range breakpoints {
if bps[i].line < 0 && !bps[i].verified {
if bp.Verified != bps[i].verified || !strings.Contains(bp.Message, bps[i].msgPrefix) {
if bp.Verified != bps[i].verified || !stringContainsCaseInsensitive(bp.Message, bps[i].msgPrefix) {
t.Errorf("got breakpoints[%d] = %#v, \nwant %#v", i, bp, bps[i])
}
continue
Expand Down Expand Up @@ -1990,7 +1990,7 @@ func TestSetBreakpoint(t *testing.T) {

// Set another breakpoint inside the loop in loop(), twice to trigger error
client.SetBreakpointsRequest(fixture.Source, []int{8, 8})
expectSetBreakpointsResponse(t, client, []Breakpoint{{8, fixture.Source, true, ""}, {-1, "", false, "Breakpoint exists"}})
expectSetBreakpointsResponse(t, client, []Breakpoint{{8, fixture.Source, true, ""}, {-1, "", false, "breakpoint exists"}})

// Continue into the loop
client.ContinueRequest(1)
Expand Down Expand Up @@ -2037,6 +2037,10 @@ func TestSetBreakpoint(t *testing.T) {
})
}

func stringContainsCaseInsensitive(got, want string) bool {
return strings.Contains(strings.ToLower(got), strings.ToLower(want))
}

// TestSetFunctionBreakpoints is inspired by service/test.TestClientServer_FindLocations.
func TestSetFunctionBreakpoints(t *testing.T) {
runTest(t, "locationsprog", func(client *daptest.Client, fixture protest.Fixture) {
Expand Down Expand Up @@ -2066,7 +2070,7 @@ func TestSetFunctionBreakpoints(t *testing.T) {
}
for i, bp := range got.Body.Breakpoints {
if bps[i].line < 0 && !bps[i].verified {
if bp.Verified != bps[i].verified || !strings.Contains(bp.Message, bps[i].errMsg) {
if bp.Verified != bps[i].verified || !stringContainsCaseInsensitive(bp.Message, bps[i].errMsg) {
t.Errorf("got breakpoints[%d] = %#v, \nwant %#v", i, bp, bps[i])
}
continue
Expand Down Expand Up @@ -2213,7 +2217,7 @@ func TestSetFunctionBreakpoints(t *testing.T) {
client.SetFunctionBreakpointsRequest([]dap.FunctionBreakpoint{
{Name: "SomeType.String"}, {Name: "(*SomeType).String"},
})
expectSetFunctionBreakpointsResponse([]Breakpoint{{14, filepath.Base(fixture.Source), true, ""}, {-1, "", false, "Breakpoint exists"}})
expectSetFunctionBreakpointsResponse([]Breakpoint{{14, filepath.Base(fixture.Source), true, ""}, {-1, "", false, "breakpoint exists"}})

// Set two breakpoints at SomeType.String and SomeType.SomeFunction.
client.SetFunctionBreakpointsRequest([]dap.FunctionBreakpoint{
Expand Down Expand Up @@ -3701,7 +3705,7 @@ func TestLaunchDebugRequest(t *testing.T) {
// BinaryInfo.Close(), but it appears that it is still in use (by Windows?)
// shortly after. gobuild.Remove has a delay to address this, but
// to avoid any test flakiness we guard against this failure here as well.
if runtime.GOOS != "windows" || !strings.Contains(rmErr, "Access is denied") {
if runtime.GOOS != "windows" || !stringContainsCaseInsensitive(rmErr, "Access is denied") {
t.Fatalf("Binary removal failure:\n%s\n", rmErr)
}
} else {
Expand Down Expand Up @@ -4014,7 +4018,7 @@ func (h *helperForSetVariable) failSetVariable0(ref int, name, value, wantErrInf
h.c.ExpectStoppedEvent(h.t)
}
resp := h.c.ExpectErrorResponse(h.t)
if got := resp.Body.Error.Format; !strings.Contains(got, wantErrInfo) {
if got := resp.Body.Error.Format; !stringContainsCaseInsensitive(got, wantErrInfo) {
h.t.Errorf("got %#v, want error string containing %v", got, wantErrInfo)
}
}
Expand Down