Prefer errors.New for unformatted errors

This commit is contained in:
Derek Parker 2015-05-01 16:27:29 -05:00
parent 6cadeb41fc
commit 1ad66660a1
14 changed files with 74 additions and 62 deletions

@ -4,6 +4,7 @@ package command
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -103,7 +104,7 @@ func CommandFunc(fn func() error) cmdfunc {
} }
func noCmdAvailable(p *proctl.DebuggedProcess, args ...string) error { func noCmdAvailable(p *proctl.DebuggedProcess, args ...string) error {
return fmt.Errorf("command not available") return errors.New("command not available")
} }
func nullCommand(p *proctl.DebuggedProcess, args ...string) error { func nullCommand(p *proctl.DebuggedProcess, args ...string) error {
@ -140,7 +141,7 @@ func threads(p *proctl.DebuggedProcess, args ...string) error {
func thread(p *proctl.DebuggedProcess, args ...string) error { func thread(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("you must specify a thread") return errors.New("you must specify a thread")
} }
oldTid := p.CurrentThread.Id oldTid := p.CurrentThread.Id
tid, err := strconv.Atoi(args[0]) tid, err := strconv.Atoi(args[0])
@ -204,7 +205,7 @@ func next(p *proctl.DebuggedProcess, args ...string) error {
func clear(p *proctl.DebuggedProcess, args ...string) error { func clear(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments") return errors.New("not enough arguments")
} }
bp, err := p.ClearByLocation(args[0]) bp, err := p.ClearByLocation(args[0])
@ -250,7 +251,7 @@ func breakpoints(p *proctl.DebuggedProcess, args ...string) error {
func breakpoint(p *proctl.DebuggedProcess, args ...string) error { func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments") return errors.New("not enough arguments")
} }
bp, err := p.BreakByLocation(args[0]) bp, err := p.BreakByLocation(args[0])
@ -265,7 +266,7 @@ func breakpoint(p *proctl.DebuggedProcess, args ...string) error {
func printVar(p *proctl.DebuggedProcess, args ...string) error { func printVar(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments") return errors.New("not enough arguments")
} }
val, err := p.EvalSymbol(args[0]) val, err := p.EvalSymbol(args[0])
@ -292,7 +293,7 @@ func filterVariables(vars []*proctl.Variable, filter *regexp.Regexp) []string {
func info(p *proctl.DebuggedProcess, args ...string) error { func info(p *proctl.DebuggedProcess, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments. expected info type [regex].") return errors.New("not enough arguments. expected info type [regex].")
} }
// Allow for optional regex // Allow for optional regex
@ -345,7 +346,7 @@ func info(p *proctl.DebuggedProcess, args ...string) error {
data = filterVariables(vars, filter) data = filterVariables(vars, filter)
default: default:
return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars") return errors.New("unsupported info type, must be args, funcs, locals, sources, or vars")
} }
// sort and output data // sort and output data

@ -2,7 +2,7 @@ package reader
import ( import (
"debug/dwarf" "debug/dwarf"
"fmt" "errors"
) )
type Reader struct { type Reader struct {
@ -57,7 +57,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
} }
} }
return nil, fmt.Errorf("unable to find function context") return nil, errors.New("unable to find function context")
} }
// SeekToType moves the reader to the type specified by the entry, // SeekToType moves the reader to the type specified by the entry,
@ -66,7 +66,7 @@ func (reader *Reader) SeekToFunction(pc uint64) (*dwarf.Entry, error) {
func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) { func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resolvePointerTypes bool) (*dwarf.Entry, error) {
offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, fmt.Errorf("entry does not have a type attribute") return nil, errors.New("entry does not have a type attribute")
} }
// Seek to the first type offset // Seek to the first type offset
@ -94,7 +94,7 @@ func (reader *Reader) SeekToType(entry *dwarf.Entry, resolveTypedefs bool, resol
reader.Seek(offset) reader.Seek(offset)
} }
return nil, fmt.Errorf("no type entry found") return nil, errors.New("no type entry found")
} }
// NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry. // NextScopeVariable moves the reader to the next debug entry that describes a local variable and returns the entry.

@ -1,13 +1,13 @@
package proctl package proctl
import "fmt" import "errors"
// TODO(darwin) // TODO(darwin)
func setHardwareBreakpoint(reg, tid int, addr uint64) error { func setHardwareBreakpoint(reg, tid int, addr uint64) error {
return fmt.Errorf("not implemented on darwin") return errors.New("not implemented on darwin")
} }
// TODO(darwin) // TODO(darwin)
func clearHardwareBreakpoint(reg, tid int) error { func clearHardwareBreakpoint(reg, tid int) error {
return fmt.Errorf("not implemented on darwin") return errors.New("not implemented on darwin")
} }

@ -15,7 +15,10 @@ int offset(int reg) {
*/ */
import "C" import "C"
import "fmt" import (
"errors"
"fmt"
)
// Sets a hardware breakpoint by setting the contents of the // Sets a hardware breakpoint by setting the contents of the
// debug register `reg` with the address of the instruction // debug register `reg` with the address of the instruction
@ -23,7 +26,7 @@ import "fmt"
// DR0-DR3. Debug register 7 is the control register. // DR0-DR3. Debug register 7 is the control register.
func setHardwareBreakpoint(reg, tid int, addr uint64) error { func setHardwareBreakpoint(reg, tid int, addr uint64) error {
if reg < 0 || reg > 3 { if reg < 0 || reg > 3 {
return fmt.Errorf("invalid debug register value") return errors.New("invalid debug register value")
} }
var ( var (

@ -4,6 +4,7 @@ import (
"debug/dwarf" "debug/dwarf"
"debug/gosym" "debug/gosym"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -582,7 +583,7 @@ func (dbp *DebuggedProcess) handleBreakpointOnThread(id int) (*ThreadContext, er
func (dbp *DebuggedProcess) run(fn func() error) error { func (dbp *DebuggedProcess) run(fn func() error) error {
if dbp.exited { if dbp.exited {
return fmt.Errorf("process has already exited") return errors.New("process has already exited")
} }
dbp.running = true dbp.running = true
dbp.halt = false dbp.halt = false

@ -6,6 +6,7 @@ import "C"
import ( import (
"debug/gosym" "debug/gosym"
"debug/macho" "debug/macho"
"errors"
"fmt" "fmt"
"os" "os"
"path/filepath" "path/filepath"
@ -49,7 +50,7 @@ func Launch(cmd []string) (*DebuggedProcess, error) {
pid := int(C.fork_exec(C.CString(argv0), &argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort)) pid := int(C.fork_exec(C.CString(argv0), &argv, &dbp.os.task, &dbp.os.portSet, &dbp.os.exceptionPort, &dbp.os.notificationPort))
if pid <= 0 { if pid <= 0 {
return nil, fmt.Errorf("could not fork/exec") return nil, errors.New("could not fork/exec")
} }
dbp.Pid = pid dbp.Pid = pid
@ -69,7 +70,7 @@ func (dbp *DebuggedProcess) requestManualStop() (err error) {
) )
kret := C.raise_exception(task, thread, exceptionPort, C.EXC_BREAKPOINT) kret := C.raise_exception(task, thread, exceptionPort, C.EXC_BREAKPOINT)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not raise mach exception") return errors.New("could not raise mach exception")
} }
return nil return nil
} }
@ -81,7 +82,7 @@ func (dbp *DebuggedProcess) updateThreadList() error {
count = C.thread_count(C.task_t(dbp.os.task)) count = C.thread_count(C.task_t(dbp.os.task))
) )
if count == -1 { if count == -1 {
return fmt.Errorf("could not get thread count") return errors.New("could not get thread count")
} }
list := make([]uint32, count) list := make([]uint32, count)
@ -89,10 +90,10 @@ func (dbp *DebuggedProcess) updateThreadList() error {
// instead of getting count above and passing in a slice // instead of getting count above and passing in a slice
kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0])) kret = C.get_threads(C.task_t(dbp.os.task), unsafe.Pointer(&list[0]))
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not get thread list") return errors.New("could not get thread list")
} }
if count < 0 { if count < 0 {
return fmt.Errorf("could not get thread list") return errors.New("could not get thread list")
} }
for _, port := range list { for _, port := range list {
@ -232,7 +233,7 @@ func (dbp *DebuggedProcess) trapWait(pid int) (*ThreadContext, error) {
} }
return nil, ManualStopError{} return nil, ManualStopError{}
case 0: case 0:
return nil, fmt.Errorf("error while waiting for task") return nil, errors.New("error while waiting for task")
} }
// Since we cannot be notified of new threads on OS X // Since we cannot be notified of new threads on OS X

@ -2,7 +2,7 @@ package proctl
// #include "threads_darwin.h" // #include "threads_darwin.h"
import "C" import "C"
import "fmt" import "errors"
type Regs struct { type Regs struct {
pc, sp uint64 pc, sp uint64
@ -19,7 +19,7 @@ func (r *Regs) SP() uint64 {
func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error { func (r *Regs) SetPC(thread *ThreadContext, pc uint64) error {
kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc)) kret := C.set_pc(thread.os.thread_act, C.uint64_t(pc))
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not set pc") return errors.New("could not set pc")
} }
return nil return nil
} }
@ -28,7 +28,7 @@ func registers(thread *ThreadContext) (Registers, error) {
var state C.x86_thread_state64_t var state C.x86_thread_state64_t
kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &state) kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &state)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return nil, fmt.Errorf("could not get registers") return nil, errors.New("could not get registers")
} }
regs := &Regs{pc: uint64(state.__rip), sp: uint64(state.__rsp)} regs := &Regs{pc: uint64(state.__rip), sp: uint64(state.__rsp)}
return regs, nil return regs, nil

@ -3,6 +3,7 @@ package proctl
// #include "threads_darwin.h" // #include "threads_darwin.h"
import "C" import "C"
import ( import (
"errors"
"fmt" "fmt"
"unsafe" "unsafe"
) )
@ -24,12 +25,12 @@ func (t *ThreadContext) Halt() error {
func (t *ThreadContext) singleStep() error { func (t *ThreadContext) singleStep() error {
kret := C.single_step(t.os.thread_act) kret := C.single_step(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not single step") return errors.New("could not single step")
} }
t.Process.trapWait(0) t.Process.trapWait(0)
kret = C.clear_trap_flag(t.os.thread_act) kret = C.clear_trap_flag(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not clear CPU trap flag") return errors.New("could not clear CPU trap flag")
} }
return nil return nil
} }
@ -41,7 +42,7 @@ func (t *ThreadContext) resume() error {
} }
kret := C.resume_thread(t.os.thread_act) kret := C.resume_thread(t.os.thread_act)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not continue thread") return errors.New("could not continue thread")
} }
return nil return nil
} }
@ -64,7 +65,7 @@ func writeMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error)
) )
if ret := C.write_memory(thread.Process.os.task, vm_addr, vm_data, length); ret < 0 { if ret := C.write_memory(thread.Process.os.task, vm_addr, vm_data, length); ret < 0 {
return 0, fmt.Errorf("could not write memory") return 0, errors.New("could not write memory")
} }
return len(data), nil return len(data), nil
} }
@ -78,7 +79,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
ret := C.read_memory(thread.Process.os.task, vm_addr, vm_data, length) ret := C.read_memory(thread.Process.os.task, vm_addr, vm_data, length)
if ret < 0 { if ret < 0 {
return 0, fmt.Errorf("could not read memory") return 0, errors.New("could not read memory")
} }
return len(data), nil return len(data), nil
} }
@ -86,7 +87,7 @@ func readMemory(thread *ThreadContext, addr uintptr, data []byte) (int, error) {
func (thread *ThreadContext) saveRegisters() (Registers, error) { func (thread *ThreadContext) saveRegisters() (Registers, error) {
kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers) kret := C.get_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return nil, fmt.Errorf("could not save register contents") return nil, errors.New("could not save register contents")
} }
return &Regs{pc: uint64(thread.os.registers.__rip), sp: uint64(thread.os.registers.__rsp)}, nil return &Regs{pc: uint64(thread.os.registers.__rip), sp: uint64(thread.os.registers.__rsp)}, nil
} }
@ -94,7 +95,7 @@ func (thread *ThreadContext) saveRegisters() (Registers, error) {
func (thread *ThreadContext) restoreRegisters() error { func (thread *ThreadContext) restoreRegisters() error {
kret := C.set_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers) kret := C.set_registers(C.mach_port_name_t(thread.os.thread_act), &thread.os.registers)
if kret != C.KERN_SUCCESS { if kret != C.KERN_SUCCESS {
return fmt.Errorf("could not save register contents") return errors.New("could not save register contents")
} }
return nil return nil
} }

@ -1,6 +1,7 @@
package proctl package proctl
import ( import (
"errors"
"fmt" "fmt"
sys "golang.org/x/sys/unix" sys "golang.org/x/sys/unix"
@ -52,7 +53,7 @@ func (t *ThreadContext) blocked() bool {
func (thread *ThreadContext) saveRegisters() (Registers, error) { func (thread *ThreadContext) saveRegisters() (Registers, error) {
if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); err != nil { if err := sys.PtraceGetRegs(thread.Id, &thread.os.registers); err != nil {
return nil, fmt.Errorf("could not save register contents") return nil, errors.New("could not save register contents")
} }
return &Regs{&thread.os.registers}, nil return &Regs{&thread.os.registers}, nil
} }

@ -5,6 +5,7 @@ import (
"debug/dwarf" "debug/dwarf"
"debug/gosym" "debug/gosym"
"encoding/binary" "encoding/binary"
"errors"
"fmt" "fmt"
"strconv" "strconv"
"strings" "strings"
@ -83,7 +84,7 @@ func (thread *ThreadContext) AllM() ([]*M, error) {
} }
m := binary.LittleEndian.Uint64(mptr) m := binary.LittleEndian.Uint64(mptr)
if m == 0 { if m == 0 {
return nil, fmt.Errorf("allm contains no M pointers") return nil, errors.New("allm contains no M pointers")
} }
procidInstructions, err := instructionsFor("procid", thread.Process, reader, true) procidInstructions, err := instructionsFor("procid", thread.Process, reader, true)
@ -190,7 +191,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
if entry.Tag == dwarf.TagMember { if entry.Tag == dwarf.TagMember {
instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte) instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
if !ok { if !ok {
return nil, fmt.Errorf("member data has no data member location attribute") return nil, errors.New("member data has no data member location attribute")
} }
// clone slice to prevent stomping on the dwarf data // clone slice to prevent stomping on the dwarf data
return append([]byte{}, instructions...), nil return append([]byte{}, instructions...), nil
@ -199,7 +200,7 @@ func instructionsForEntry(entry *dwarf.Entry) ([]byte, error) {
// non-member // non-member
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return nil, fmt.Errorf("entry has no location attribute") return nil, errors.New("entry has no location attribute")
} }
// clone slice to prevent stomping on the dwarf data // clone slice to prevent stomping on the dwarf data
@ -224,7 +225,7 @@ func parseAllMPtr(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, fmt.Errorf("type assertion failed") return 0, errors.New("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
@ -320,7 +321,7 @@ func allglenval(dbp *DebuggedProcess, reader *dwarf.Reader) (uint64, error) {
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, fmt.Errorf("type assertion failed") return 0, errors.New("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
@ -341,7 +342,7 @@ func addressFor(dbp *DebuggedProcess, name string, reader *dwarf.Reader) (uint64
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return 0, fmt.Errorf("type assertion failed") return 0, errors.New("type assertion failed")
} }
addr, err := op.ExecuteStackProgram(0, instructions) addr, err := op.ExecuteStackProgram(0, instructions)
if err != nil { if err != nil {
@ -358,7 +359,7 @@ func offsetFor(name string, reader *dwarf.Reader, parentinstr []byte) (uint64, e
} }
instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte) instructions, ok := entry.Val(dwarf.AttrDataMemberLoc).([]byte)
if !ok { if !ok {
return 0, fmt.Errorf("type assertion failed") return 0, errors.New("type assertion failed")
} }
offset, err := op.ExecuteStackProgram(0, append(parentinstr, instructions...)) offset, err := op.ExecuteStackProgram(0, append(parentinstr, instructions...))
if err != nil { if err != nil {
@ -489,7 +490,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Get parent variable name // Get parent variable name
parentName, ok := parentEntry.Val(dwarf.AttrName).(string) parentName, ok := parentEntry.Val(dwarf.AttrName).(string)
if !ok { if !ok {
return nil, fmt.Errorf("unable to retrive variable name") return nil, errors.New("unable to retrive variable name")
} }
// Seek reader to the type information so members can be iterated // Seek reader to the type information so members can be iterated
@ -522,7 +523,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
offset, ok := memberEntry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := memberEntry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, fmt.Errorf("type assertion failed") return nil, errors.New("type assertion failed")
} }
data := thread.Process.dwarf data := thread.Process.dwarf
@ -549,7 +550,7 @@ func (thread *ThreadContext) evaluateStructMember(parentEntry *dwarf.Entry, read
// Extracts the name, type, and value of a variable from a dwarf entry // Extracts the name, type, and value of a variable from a dwarf entry
func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Variable, error) { func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Variable, error) {
if entry == nil { if entry == nil {
return nil, fmt.Errorf("invalid entry") return nil, errors.New("invalid entry")
} }
if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable { if entry.Tag != dwarf.TagFormalParameter && entry.Tag != dwarf.TagVariable {
@ -558,12 +559,12 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
n, ok := entry.Val(dwarf.AttrName).(string) n, ok := entry.Val(dwarf.AttrName).(string)
if !ok { if !ok {
return nil, fmt.Errorf("type assertion failed") return nil, errors.New("type assertion failed")
} }
offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset) offset, ok := entry.Val(dwarf.AttrType).(dwarf.Offset)
if !ok { if !ok {
return nil, fmt.Errorf("type assertion failed") return nil, errors.New("type assertion failed")
} }
data := thread.Process.dwarf data := thread.Process.dwarf
@ -574,7 +575,7 @@ func (thread *ThreadContext) extractVariableFromEntry(entry *dwarf.Entry) (*Vari
instructions, ok := entry.Val(dwarf.AttrLocation).([]byte) instructions, ok := entry.Val(dwarf.AttrLocation).([]byte)
if !ok { if !ok {
return nil, fmt.Errorf("type assertion failed") return nil, errors.New("type assertion failed")
} }
val, err := thread.extractValue(instructions, 0, t, true) val, err := thread.extractValue(instructions, 0, t, true)
@ -910,7 +911,7 @@ func (thread *ThreadContext) readFloat(addr uintptr, size int64) (string, error)
return strconv.FormatFloat(n, 'f', -1, int(size)*8), nil return strconv.FormatFloat(n, 'f', -1, int(size)*8), nil
} }
return "", fmt.Errorf("could not read float") return "", errors.New("could not read float")
} }
func (thread *ThreadContext) readBool(addr uintptr) (string, error) { func (thread *ThreadContext) readBool(addr uintptr) (string, error) {
@ -953,7 +954,7 @@ func (thread *ThreadContext) readFunctionPtr(addr uintptr) (string, error) {
n, ok := entry.Val(dwarf.AttrName).(string) n, ok := entry.Val(dwarf.AttrName).(string)
if !ok { if !ok {
return "", fmt.Errorf("Unable to retrieve function name") return "", errors.New("Unable to retrieve function name")
} }
return n, nil return n, nil

@ -1,6 +1,7 @@
package debugger package debugger
import ( import (
"errors"
"fmt" "fmt"
"log" "log"
"regexp" "regexp"
@ -65,7 +66,7 @@ func New(config *Config) *Debugger {
// operation. // operation.
func (d *Debugger) withProcess(f func(*proctl.DebuggedProcess) error) error { func (d *Debugger) withProcess(f func(*proctl.DebuggedProcess) error) error {
if !d.running { if !d.running {
return fmt.Errorf("debugger isn't running") return errors.New("debugger isn't running")
} }
result := make(chan error) result := make(chan error)
@ -161,7 +162,7 @@ func (d *Debugger) Run() error {
// Detach stops the debugger. // Detach stops the debugger.
func (d *Debugger) Detach(kill bool) error { func (d *Debugger) Detach(kill bool) error {
if !d.running { if !d.running {
return fmt.Errorf("debugger isn't running") return errors.New("debugger isn't running")
} }
d.stop <- stopSignal{KillProcess: kill} d.stop <- stopSignal{KillProcess: kill}
@ -205,7 +206,7 @@ func (d *Debugger) CreateBreakPoint(requestedBp *api.BreakPoint) (*api.BreakPoin
case len(requestedBp.FunctionName) > 0: case len(requestedBp.FunctionName) > 0:
loc = requestedBp.FunctionName loc = requestedBp.FunctionName
default: default:
return fmt.Errorf("no file or function name specified") return errors.New("no file or function name specified")
} }
bp, breakError := p.BreakByLocation(loc) bp, breakError := p.BreakByLocation(loc)

@ -4,6 +4,7 @@ package terminal
import ( import (
"bufio" "bufio"
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -106,7 +107,7 @@ func CommandFunc(fn func() error) cmdfunc {
} }
func noCmdAvailable(client service.Client, args ...string) error { func noCmdAvailable(client service.Client, args ...string) error {
return fmt.Errorf("command not available") return errors.New("command not available")
} }
func nullCommand(client service.Client, args ...string) error { func nullCommand(client service.Client, args ...string) error {
@ -220,7 +221,7 @@ func next(client service.Client, args ...string) error {
func clear(client service.Client, args ...string) error { func clear(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments") return errors.New("not enough arguments")
} }
id, err := strconv.Atoi(args[0]) id, err := strconv.Atoi(args[0])
@ -272,7 +273,7 @@ func breakpoints(client service.Client, args ...string) error {
func breakpoint(client service.Client, args ...string) error { func breakpoint(client service.Client, args ...string) error {
if len(args) != 1 { if len(args) != 1 {
return fmt.Errorf("argument must be either a function name or <file:line>") return errors.New("argument must be either a function name or <file:line>")
} }
requestedBp := &api.BreakPoint{} requestedBp := &api.BreakPoint{}
tokens := strings.Split(args[0], ":") tokens := strings.Split(args[0], ":")
@ -288,7 +289,7 @@ func breakpoint(client service.Client, args ...string) error {
requestedBp.File = file requestedBp.File = file
requestedBp.Line = line requestedBp.Line = line
default: default:
return fmt.Errorf("invalid line reference") return errors.New("invalid line reference")
} }
bp, err := client.CreateBreakPoint(requestedBp) bp, err := client.CreateBreakPoint(requestedBp)
@ -302,7 +303,7 @@ func breakpoint(client service.Client, args ...string) error {
func printVar(client service.Client, args ...string) error { func printVar(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments") return errors.New("not enough arguments")
} }
val, err := client.EvalSymbol(args[0]) val, err := client.EvalSymbol(args[0])
@ -326,7 +327,7 @@ func filterVariables(vars []api.Variable, filter *regexp.Regexp) []string {
func info(client service.Client, args ...string) error { func info(client service.Client, args ...string) error {
if len(args) == 0 { if len(args) == 0 {
return fmt.Errorf("not enough arguments. expected info type [regex].") return errors.New("not enough arguments. expected info type [regex].")
} }
// Allow for optional regex // Allow for optional regex
@ -397,7 +398,7 @@ func info(client service.Client, args ...string) error {
} }
default: default:
return fmt.Errorf("unsupported info type, must be args, funcs, locals, sources, or vars") return errors.New("unsupported info type, must be args, funcs, locals, sources, or vars")
} }
// sort and output data // sort and output data

@ -1,7 +1,7 @@
package terminal package terminal
import ( import (
"fmt" "errors"
"testing" "testing"
"github.com/derekparker/delve/service" "github.com/derekparker/delve/service"
@ -25,7 +25,7 @@ func TestCommandDefault(t *testing.T) {
func TestCommandReplay(t *testing.T) { func TestCommandReplay(t *testing.T) {
cmds := DebugCommands(nil) cmds := DebugCommands(nil)
cmds.Register("foo", func(client service.Client, args ...string) error { return fmt.Errorf("registered command") }, "foo command") cmds.Register("foo", func(client service.Client, args ...string) error { return errors.New("registered command") }, "foo command")
cmd := cmds.Find("foo") cmd := cmds.Find("foo")
err := cmd(nil) err := cmd(nil)

@ -1,6 +1,7 @@
package terminal package terminal
import ( import (
"errors"
"fmt" "fmt"
"io" "io"
"os" "os"
@ -62,7 +63,7 @@ func (t *Term) Run() (error, int) {
if err == io.EOF { if err == io.EOF {
err, status = handleExit(t.client, t) err, status = handleExit(t.client, t)
} }
err, status = fmt.Errorf("Prompt for input failed.\n"), 1 err, status = errors.New("Prompt for input failed.\n"), 1
break break
} }