global: switch to using %w instead of %v for Errorf

Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
This commit is contained in:
Jason A. Donenfeld 2020-11-07 21:56:32 +01:00
parent c192b2eeec
commit 82128c47d9
6 changed files with 34 additions and 34 deletions

View file

@ -287,7 +287,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
return nil, fmt.Errorf("Unable to put into IFHEAD mode: %v", errno)
return nil, fmt.Errorf("Unable to put into IFHEAD mode: %w", errno)
}
// Open control sockets
@ -328,7 +328,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
return nil, fmt.Errorf("Unable to get nd6 flags for %s: %v", assignedName, errno)
return nil, fmt.Errorf("Unable to get nd6 flags for %s: %w", assignedName, errno)
}
ndireq.Flags = ndireq.Flags &^ ND6_IFF_AUTO_LINKLOCAL
ndireq.Flags = ndireq.Flags | ND6_IFF_NO_DAD
@ -341,7 +341,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
return nil, fmt.Errorf("Unable to set nd6 flags for %s: %v", assignedName, errno)
return nil, fmt.Errorf("Unable to set nd6 flags for %s: %w", assignedName, errno)
}
// Rename the interface
@ -359,7 +359,7 @@ func CreateTUN(name string, mtu int) (Device, error) {
if errno != 0 {
tunFile.Close()
tunDestroy(assignedName)
return nil, fmt.Errorf("Failed to rename %s to %s: %v", assignedName, name, errno)
return nil, fmt.Errorf("Failed to rename %s to %s: %w", assignedName, name, errno)
}
return CreateTUNFromFile(tunFile, mtu)

View file

@ -49,7 +49,7 @@ func init() {
var err error
WintunPool, err = wintun.MakePool("WireGuard")
if err != nil {
panic(fmt.Errorf("Failed to make pool: %v", err))
panic(fmt.Errorf("Failed to make pool: %w", err))
}
}
@ -81,12 +81,12 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID, mtu
// If so, we delete it, in case it has weird residual configuration.
_, err = wt.Delete(true)
if err != nil {
return nil, fmt.Errorf("Error deleting already existing interface: %v", err)
return nil, fmt.Errorf("Error deleting already existing interface: %w", err)
}
}
wt, _, err = WintunPool.CreateAdapter(ifname, requestedGUID)
if err != nil {
return nil, fmt.Errorf("Error creating interface: %v", err)
return nil, fmt.Errorf("Error creating interface: %w", err)
}
forcedMTU := 1420
@ -106,7 +106,7 @@ func CreateTUNWithRequestedGUID(ifname string, requestedGUID *windows.GUID, mtu
if err != nil {
_, err = tun.wt.Delete(false)
close(tun.events)
return nil, fmt.Errorf("Error starting session: %v", err)
return nil, fmt.Errorf("Error starting session: %w", err)
}
tun.readWait = tun.session.ReadWaitEvent()
return tun, nil
@ -179,7 +179,7 @@ retry:
case windows.ERROR_INVALID_DATA:
return 0, errors.New("Send ring corrupt")
}
return 0, fmt.Errorf("Read failed: %v", err)
return 0, fmt.Errorf("Read failed: %w", err)
}
}
@ -207,7 +207,7 @@ func (tun *NativeTun) Write(buff []byte, offset int) (int, error) {
case windows.ERROR_BUFFER_OVERFLOW:
return 0, nil // Dropping when ring is full.
}
return 0, fmt.Errorf("Write failed: %v", err)
return 0, fmt.Errorf("Write failed: %w", err)
}
// LUID returns Windows interface instance ID.

View file

@ -39,15 +39,15 @@ func (d *lazyDLL) Load() error {
const ourModule windows.Handle = 0
resInfo, err := resource.FindByName(ourModule, d.Name, resource.RT_RCDATA)
if err != nil {
return fmt.Errorf("Unable to find \"%v\" RCDATA resource: %v", d.Name, err)
return fmt.Errorf("Unable to find \"%v\" RCDATA resource: %w", d.Name, err)
}
data, err := resource.Load(ourModule, resInfo)
if err != nil {
return fmt.Errorf("Unable to load resource: %v", err)
return fmt.Errorf("Unable to load resource: %w", err)
}
module, err := memmod.LoadLibrary(data)
if err != nil {
return fmt.Errorf("Unable to load library: %v", err)
return fmt.Errorf("Unable to load library: %w", err)
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&d.module)), unsafe.Pointer(module))
@ -77,11 +77,11 @@ func (p *lazyProc) Find() error {
err := p.dll.Load()
if err != nil {
return fmt.Errorf("Error loading %v DLL: %v", p.dll.Name, err)
return fmt.Errorf("Error loading %v DLL: %w", p.dll.Name, err)
}
addr, err := p.dll.module.ProcAddressByName(p.Name)
if err != nil {
return fmt.Errorf("Error getting %v address: %v", p.Name, err)
return fmt.Errorf("Error getting %v address: %w", p.Name, err)
}
atomic.StorePointer((*unsafe.Pointer)(unsafe.Pointer(&p.addr)), unsafe.Pointer(addr))

View file

@ -55,7 +55,7 @@ func (module *Module) copySections(address uintptr, size uintptr, old_headers *I
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
return fmt.Errorf("Error allocating section: %v", err)
return fmt.Errorf("Error allocating section: %w", err)
}
// Always use position from file to support alignments smaller than page size (allocation above will align to page size).
@ -80,7 +80,7 @@ func (module *Module) copySections(address uintptr, size uintptr, old_headers *I
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
return fmt.Errorf("Error allocating memory block: %v", err)
return fmt.Errorf("Error allocating memory block: %w", err)
}
// Always use position from file to support alignments smaller than page size (allocation above will align to page size).
@ -153,7 +153,7 @@ func (module *Module) finalizeSection(sectionData *sectionFinalizeData) error {
var oldProtect uint32
err := windows.VirtualProtect(sectionData.address, sectionData.size, protect, &oldProtect)
if err != nil {
return fmt.Errorf("Error protecting memory page: %v", err)
return fmt.Errorf("Error protecting memory page: %w", err)
}
return nil
@ -188,7 +188,7 @@ func (module *Module) finalizeSections() error {
err := module.finalizeSection(&sectionData)
if err != nil {
return fmt.Errorf("Error finalizing section: %v", err)
return fmt.Errorf("Error finalizing section: %w", err)
}
sectionData.address = sectionAddress
sectionData.alignedAddress = alignedAddress
@ -198,7 +198,7 @@ func (module *Module) finalizeSections() error {
sectionData.last = true
err := module.finalizeSection(&sectionData)
if err != nil {
return fmt.Errorf("Error finalizing section: %v", err)
return fmt.Errorf("Error finalizing section: %w", err)
}
return nil
}
@ -294,7 +294,7 @@ func (module *Module) performBaseRelocation(delta uintptr) (relocated bool, err
}
default:
return false, fmt.Errorf("Unsupported relocation: %v", relType)
return false, fmt.Errorf("Unsupported relocation: %w", relType)
}
}
@ -315,7 +315,7 @@ func (module *Module) buildImportTable() error {
for !isBadReadPtr(uintptr(unsafe.Pointer(importDesc)), unsafe.Sizeof(*importDesc)) && importDesc.Name != 0 {
handle, err := loadLibraryA((*byte)(a2p(module.codeBase + uintptr(importDesc.Name))))
if err != nil {
return fmt.Errorf("Error loading module: %v", err)
return fmt.Errorf("Error loading module: %w", err)
}
var thunkRef, funcRef *uintptr
if importDesc.OriginalFirstThunk() != 0 {
@ -335,7 +335,7 @@ func (module *Module) buildImportTable() error {
}
if err != nil {
windows.FreeLibrary(handle)
return fmt.Errorf("Error getting function address: %v", err)
return fmt.Errorf("Error getting function address: %w", err)
}
thunkRef = (*uintptr)(a2p(uintptr(unsafe.Pointer(thunkRef)) + unsafe.Sizeof(*thunkRef)))
funcRef = (*uintptr)(a2p(uintptr(unsafe.Pointer(funcRef)) + unsafe.Sizeof(*funcRef)))
@ -435,13 +435,13 @@ func LoadLibrary(data []byte) (module *Module, err error) {
windows.MEM_RESERVE|windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
err = fmt.Errorf("Error allocating code: %v", err)
err = fmt.Errorf("Error allocating code: %w", err)
return
}
}
err = module.check4GBBoundaries(alignedImageSize)
if err != nil {
err = fmt.Errorf("Error reallocating code: %v", err)
err = fmt.Errorf("Error reallocating code: %w", err)
return
}
@ -455,7 +455,7 @@ func LoadLibrary(data []byte) (module *Module, err error) {
windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
err = fmt.Errorf("Error allocating headers: %v", err)
err = fmt.Errorf("Error allocating headers: %w", err)
return
}
// Copy PE header to code.
@ -468,7 +468,7 @@ func LoadLibrary(data []byte) (module *Module, err error) {
// Copy sections from DLL file block to new memory location.
err = module.copySections(addr, size, oldHeader)
if err != nil {
err = fmt.Errorf("Error copying sections: %v", err)
err = fmt.Errorf("Error copying sections: %w", err)
return
}
@ -477,7 +477,7 @@ func LoadLibrary(data []byte) (module *Module, err error) {
if locationDelta != 0 {
module.isRelocated, err = module.performBaseRelocation(locationDelta)
if err != nil {
err = fmt.Errorf("Error relocating module: %v", err)
err = fmt.Errorf("Error relocating module: %w", err)
return
}
} else {
@ -487,14 +487,14 @@ func LoadLibrary(data []byte) (module *Module, err error) {
// Load required dlls and adjust function table of imports.
err = module.buildImportTable()
if err != nil {
err = fmt.Errorf("Error building import table: %v", err)
err = fmt.Errorf("Error building import table: %w", err)
return
}
// Mark memory pages depending on section headers and release sections that are marked as "discardable".
err = module.finalizeSections()
if err != nil {
err = fmt.Errorf("Error finalizing sections: %v", err)
err = fmt.Errorf("Error finalizing sections: %w", err)
return
}

View file

@ -29,7 +29,7 @@ func (module *Module) check4GBBoundaries(alignedImageSize uintptr) (err error) {
windows.MEM_RESERVE|windows.MEM_COMMIT,
windows.PAGE_READWRITE)
if err != nil {
return fmt.Errorf("Error allocating memory block: %v", err)
return fmt.Errorf("Error allocating memory block: %w", err)
}
}
return

View file

@ -74,17 +74,17 @@ func FindByName(module windows.Handle, name string, resType *uint16) (resInfo wi
func Load(module, resInfo windows.Handle) (data []byte, err error) {
size, err := sizeofResource(module, resInfo)
if err != nil {
err = fmt.Errorf("Unable to size resource: %v", err)
err = fmt.Errorf("Unable to size resource: %w", err)
return
}
resData, err := loadResource(module, resInfo)
if err != nil {
err = fmt.Errorf("Unable to load resource: %v", err)
err = fmt.Errorf("Unable to load resource: %w", err)
return
}
ptr, err := lockResource(resData)
if err != nil {
err = fmt.Errorf("Unable to lock resource: %v", err)
err = fmt.Errorf("Unable to lock resource: %w", err)
return
}
unsafeSlice(unsafe.Pointer(&data), unsafe.Pointer(ptr), int(size))