service/dap: refactor funcs always returning nil error (#3357)

This commit is contained in:
Oleksandr Redko 2023-05-08 20:41:14 +03:00 committed by GitHub
parent 5c7049b7b1
commit a57c60e43a
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23

@ -336,7 +336,7 @@ func NewSession(conn io.ReadWriteCloser, config *Config, debugger *debugger.Debu
// If user-specified options are provided via Launch/AttachRequest, // If user-specified options are provided via Launch/AttachRequest,
// we override the defaults for optional args. // we override the defaults for optional args.
func (s *Session) setLaunchAttachArgs(args LaunchAttachCommonConfig) error { func (s *Session) setLaunchAttachArgs(args LaunchAttachCommonConfig) {
s.args.stopOnEntry = args.StopOnEntry s.args.stopOnEntry = args.StopOnEntry
if depth := args.StackTraceDepth; depth > 0 { if depth := args.StackTraceDepth; depth > 0 {
s.args.StackTraceDepth = depth s.args.StackTraceDepth = depth
@ -355,7 +355,6 @@ func (s *Session) setLaunchAttachArgs(args LaunchAttachCommonConfig) error {
s.args.substitutePathClientToServer = clientToServer s.args.substitutePathClientToServer = clientToServer
s.args.substitutePathServerToClient = serverToClient s.args.substitutePathServerToClient = serverToClient
} }
return nil
} }
// Stop stops the DAP debugger service, closes the listener and the client // Stop stops the DAP debugger service, closes the listener and the client
@ -1000,10 +999,7 @@ func (s *Session) onLaunchRequest(request *dap.LaunchRequest) {
} }
s.config.ProcessArgs = append([]string{debugbinary}, args.Args...) s.config.ProcessArgs = append([]string{debugbinary}, args.Args...)
if err := s.setLaunchAttachArgs(args.LaunchAttachCommonConfig); err != nil { s.setLaunchAttachArgs(args.LaunchAttachCommonConfig)
s.sendShowUserErrorResponse(request.Request, FailedToLaunch, "Failed to launch", err.Error())
return
}
if args.Cwd == "" { if args.Cwd == "" {
if args.Mode == "test" { if args.Mode == "test" {
@ -1782,10 +1778,7 @@ func (s *Session) onAttachRequest(request *dap.AttachRequest) {
return return
} }
if err := s.setLaunchAttachArgs(args.LaunchAttachCommonConfig); err != nil { s.setLaunchAttachArgs(args.LaunchAttachCommonConfig)
s.sendShowUserErrorResponse(request.Request, FailedToAttach, "Failed to attach", err.Error())
return
}
// Notify the client that the debugger is ready to start accepting // Notify the client that the debugger is ready to start accepting
// configuration requests for setting breakpoints, etc. The client // configuration requests for setting breakpoints, etc. The client
@ -2142,11 +2135,7 @@ func (s *Session) onVariablesRequest(request *dap.VariablesRequest) {
children = append(children, named...) children = append(children, named...)
} }
if request.Arguments.Filter == "indexed" || request.Arguments.Filter == "" { if request.Arguments.Filter == "indexed" || request.Arguments.Filter == "" {
indexed, err := s.childrenToDAPVariables(v) indexed := s.childrenToDAPVariables(v)
if err != nil {
s.sendErrorResponse(request.Request, UnableToLookupVariable, "Unable to lookup variable", err.Error())
return
}
children = append(children, indexed...) children = append(children, indexed...)
} }
response := &dap.VariablesResponse{ response := &dap.VariablesResponse{
@ -2192,7 +2181,7 @@ func getIndexedVariableCount(v *proc.Variable) int {
} }
// childrenToDAPVariables returns the DAP presentation of the referenced variable's children. // childrenToDAPVariables returns the DAP presentation of the referenced variable's children.
func (s *Session) childrenToDAPVariables(v *fullyQualifiedVariable) ([]dap.Variable, error) { func (s *Session) childrenToDAPVariables(v *fullyQualifiedVariable) []dap.Variable {
// TODO(polina): consider convertVariableToString instead of convertVariable // TODO(polina): consider convertVariableToString instead of convertVariable
// and avoid unnecessary creation of variable handles when this is called to // and avoid unnecessary creation of variable handles when this is called to
// compute evaluate names when this is called from onSetVariableRequest. // compute evaluate names when this is called from onSetVariableRequest.
@ -2340,7 +2329,7 @@ func (s *Session) childrenToDAPVariables(v *fullyQualifiedVariable) ([]dap.Varia
} }
} }
} }
return children, nil return children
} }
func getNamedVariableCount(v *proc.Variable) int { func getNamedVariableCount(v *proc.Variable) int {
@ -2833,10 +2822,7 @@ func (s *Session) onReverseContinueRequest(request *dap.ReverseContinueRequest,
// computeEvaluateName finds the named child, and computes its evaluate name. // computeEvaluateName finds the named child, and computes its evaluate name.
func (s *Session) computeEvaluateName(v *fullyQualifiedVariable, cname string) (string, error) { func (s *Session) computeEvaluateName(v *fullyQualifiedVariable, cname string) (string, error) {
children, err := s.childrenToDAPVariables(v) children := s.childrenToDAPVariables(v)
if err != nil {
return "", err
}
for _, c := range children { for _, c := range children {
if c.Name == cname { if c.Name == cname {
if c.EvaluateName != "" { if c.EvaluateName != "" {