Stop using github.com/pkg/errors

This commit is contained in:
Tulir Asokan 2020-10-05 22:38:34 +03:00
parent 6315dac2eb
commit 491d8b232e
5 changed files with 24 additions and 71 deletions

View file

@ -25,7 +25,6 @@ import (
"fmt"
"time"
"github.com/pkg/errors"
"maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix"
@ -171,15 +170,15 @@ func (helper *CryptoHelper) Encrypt(roomID id.RoomID, evtType event.Type, conten
helper.log.Debugfln("Got %v while encrypting event for %s, sharing group session and trying again...", err, roomID)
users, err := helper.store.GetRoomMembers(roomID)
if err != nil {
return nil, errors.Wrap(err, "failed to get room member list")
return nil, fmt.Errorf("failed to get room member list: %w", err)
}
err = helper.mach.ShareGroupSession(roomID, users)
if err != nil {
return nil, errors.Wrap(err, "failed to share group session")
return nil, fmt.Errorf("failed to share group session: %w", err)
}
encrypted, err = helper.mach.EncryptMegolmEvent(roomID, evtType, &content)
if err != nil {
return nil, errors.Wrap(err, "failed to encrypt event after re-sharing group session")
return nil, fmt.Errorf("failed to encrypt event after re-sharing group session: %w", err)
}
}
return encrypted, nil

View file

@ -20,10 +20,9 @@ import (
"crypto/hmac"
"crypto/sha512"
"encoding/hex"
"errors"
"time"
"github.com/pkg/errors"
"github.com/Rhymen/go-whatsapp"
"maunium.net/go/mautrix"

6
go.mod
View file

@ -8,7 +8,7 @@ require (
github.com/gorilla/websocket v1.4.2
github.com/lib/pq v1.7.0
github.com/mattn/go-sqlite3 v1.14.0
github.com/pkg/errors v0.9.1
github.com/pkg/errors v0.8.1
github.com/prometheus/client_golang v1.7.0
github.com/shurcooL/sanitized_anchor_name v1.0.0 // indirect
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
@ -16,7 +16,7 @@ require (
gopkg.in/yaml.v2 v2.3.0
maunium.net/go/mauflag v1.0.0
maunium.net/go/maulogger/v2 v2.1.1
maunium.net/go/mautrix v0.7.9
maunium.net/go/mautrix v0.7.10
)
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.9
replace github.com/Rhymen/go-whatsapp => github.com/tulir/go-whatsapp v0.3.10

53
go.sum
View file

@ -69,8 +69,6 @@ github.com/modern-go/reflect2 v1.0.1/go.mod h1:bx2lNnkwVCuqBIxFjflWJWanXIb3Rllmb
github.com/mwitkow/go-conntrack v0.0.0-20161129095857-cc309e4a2223/go.mod h1:qRWi+5nqEBWmkhHvq77mSJWrCKwh8bxhgT7d/eI7P4U=
github.com/pkg/errors v0.8.0/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.8.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pkg/errors v0.9.1 h1:FEBLx1zS214owpjy7qsBeixbURkuhQAwrK5UwLGTwt4=
github.com/pkg/errors v0.9.1/go.mod h1:bwawxfHBFNV+L2hUp1rHADufV3IMtnDRdf1r5NINEl0=
github.com/pmezard/go-difflib v1.0.0/go.mod h1:iKH77koFhYxTK1pcRnkKkqfTogsbg7gZNVY4sRDYZ/4=
github.com/prometheus/client_golang v0.9.1/go.mod h1:7SWBe2y4D6OKWSNQJUaRYU/AaXPKyh/dDVn+NZz0KFw=
github.com/prometheus/client_golang v1.0.0/go.mod h1:db9x61etRT2tGnBNRi70OPL5FsnadC4Ky3P0J6CfImo=
@ -111,28 +109,13 @@ github.com/tidwall/pretty v1.0.1 h1:WE4RBSZ1x6McVVC8S/Md+Qse8YUv6HRObAx6ke00NY8=
github.com/tidwall/pretty v1.0.1/go.mod h1:XNkn88O1ChpSDQmQeStsy+sBenx6DDtFZJxhVysOjyk=
github.com/tidwall/sjson v1.1.1 h1:7h1vk049Jnd5EH9NyzNiEuwYW4b5qgreBbqRC19AS3U=
github.com/tidwall/sjson v1.1.1/go.mod h1:yvVuSnpEQv5cYIrO+AT6kw4QVfd5SDZoGIS7/5+fZFs=
github.com/tulir/go-whatsapp v0.3.2 h1:SPNyB/yxaYY1Sca75OttsrsPNMPZzpjhwTzJy6Dx9ig=
github.com/tulir/go-whatsapp v0.3.2/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.3 h1:R/SRdgjG1rdmegxx1CE2KmVBKzI8xvC9EE+NNApb4rA=
github.com/tulir/go-whatsapp v0.3.3/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.4 h1:MnfKMj8QOZpZ0SBRXOzhTmoMRF+KqsSDLI+R/glw3rs=
github.com/tulir/go-whatsapp v0.3.4/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.5 h1:cFw8MWhoLTqR0h2kSkSvz866rggRIAx4X2l8I65gARk=
github.com/tulir/go-whatsapp v0.3.5/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.6 h1:RtyNh8TFX48ClMvi2J8oS3qmH7b1t9SIKA5jucG2lbk=
github.com/tulir/go-whatsapp v0.3.6/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.7 h1:6YoHsAlO+Y1SnU0bOntDmuvJQziEnBjFKO+1fOH2VIw=
github.com/tulir/go-whatsapp v0.3.7/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.8 h1:cRPyYhtgokUyeE2wsSlRpsw9qddi0Giun+kn9fGsl/M=
github.com/tulir/go-whatsapp v0.3.8/go.mod h1:7yGOBdWidM6gsmbAFwgkwHEIhzVrm01+6UbImpMWfTM=
github.com/tulir/go-whatsapp v0.3.9 h1:fs2G8TMsSJ2y93UxM9pnFHGxMjKrdFAyavqG8MxpNQA=
github.com/tulir/go-whatsapp v0.3.9/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
github.com/tulir/go-whatsapp v0.3.10 h1:LfzRj6V3dshKemad3HZsgYgKAZtaT0wNITmobJYAbro=
github.com/tulir/go-whatsapp v0.3.10/go.mod h1:U5+sm33vrv3wz62YyRM/VS7q2ObXkxU4Xqj/3KOmN9o=
golang.org/x/crypto v0.0.0-20180904163835-0709b304e793/go.mod h1:6SG95UA2DQfeDnfUPMdvaQW0Q7yPrPDi9nlGo2tz2b4=
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9 h1:vEg9joUBmeBcK9iSJftGNf3coIG4HqZElCPehJsfAYM=
golang.org/x/crypto v0.0.0-20200604202706-70a84ac30bf9/go.mod h1:LzIPMQfyMNhhGPhUkYOs5KpL4U8rLKemX1yGLhDgUto=
golang.org/x/exp v0.0.0-20190121172915-509febef88a4/go.mod h1:CJ0aWSM057203Lf6IL+f9T1iT9GByDxfZKAQTCR3kQA=
golang.org/x/image v0.0.0-20200618115811-c13761719519 h1:1e2ufUJNM3lCHEY5jIgac/7UTjd6cgJNdatjPdFWf34=
golang.org/x/image v0.0.0-20200618115811-c13761719519/go.mod h1:FeLwcggjj3mMvU+oOTbSwawSJRM1uh48EjtB4UJZlP0=
golang.org/x/lint v0.0.0-20181026193005-c67002cb31c3/go.mod h1:UVdnD1Gm6xHRNCYTkRU2/jEulfH38KcIWyp/GAMgvoE=
golang.org/x/lint v0.0.0-20190227174305-5b3e6a55c961/go.mod h1:wehouNa3lNwaWXcvxsM5YxQ5yQlVC4a0KAMCusXpPoU=
@ -205,33 +188,5 @@ maunium.net/go/mauflag v1.0.0 h1:YiaRc0tEI3toYtJMRIfjP+jklH45uDHtT80nUamyD4M=
maunium.net/go/mauflag v1.0.0/go.mod h1:nLivPOpTpHnpzEh8jEdSL9UqO9+/KBJFmNRlwKfkPeA=
maunium.net/go/maulogger/v2 v2.1.1 h1:NAZNc6XUFJzgzfewCzVoGkxNAsblLCSSEdtDuIjP0XA=
maunium.net/go/maulogger/v2 v2.1.1/go.mod h1:TYWy7wKwz/tIXTpsx8G3mZseIRiC5DoMxSZazOHy68A=
maunium.net/go/mautrix v0.5.4 h1:FX5LXZjdkwjA0ZStVsQo5hyzteiUUNejVvbwv0aZfw4=
maunium.net/go/mautrix v0.5.4/go.mod h1:FLbMANzwqlsX2Fgm7SDe+E4I3wSa4UxJRKqS5wGkCwA=
maunium.net/go/mautrix v0.5.5 h1:e0Pql1FdxoNUudx2oXo1gZHMrqIh5MC72cdXEPIrYLA=
maunium.net/go/mautrix v0.5.5/go.mod h1:FLbMANzwqlsX2Fgm7SDe+E4I3wSa4UxJRKqS5wGkCwA=
maunium.net/go/mautrix v0.5.6 h1:XCpyj3yeSOXpX+HMbF+3rdja97efMv/XchsOHylKdXY=
maunium.net/go/mautrix v0.5.6/go.mod h1:FLbMANzwqlsX2Fgm7SDe+E4I3wSa4UxJRKqS5wGkCwA=
maunium.net/go/mautrix v0.5.7 h1:tyRwllz3SZvMfD2YjaJPWopxmUCxZgQ2hl5/3/loHTE=
maunium.net/go/mautrix v0.5.7/go.mod h1:FLbMANzwqlsX2Fgm7SDe+E4I3wSa4UxJRKqS5wGkCwA=
maunium.net/go/mautrix v0.5.8 h1:jOE3U8WYSIc4qbYvyVaDhOaQcB3sDPN5A2zQ93YixZ0=
maunium.net/go/mautrix v0.5.8/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.6.0 h1:V32l4aygKk2XcH3fi8Yd0pFeSyYZJNRIvr8vdA2GtC8=
maunium.net/go/mautrix v0.6.0/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.6.1 h1:OFxAEnjEtkstE5J3RLv+vVrUORY6UTXV8pD/qWRBTPI=
maunium.net/go/mautrix v0.6.1/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.0-rc.2 h1:139raRbbLft9i+g0zGVOT8rrHKRQmeo0SsZnFpZDEXE=
maunium.net/go/mautrix v0.7.0-rc.2/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.0-rc.3 h1:GVmrVvY5vDASMyZ2xJ9kNynWsgqKl1yerKP7c6RsM7o=
maunium.net/go/mautrix v0.7.0-rc.3/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.0 h1:9Wxs5S4Wl4S99dbBwfLZYAe/sP7VKaFikw9Ocf88kfk=
maunium.net/go/mautrix v0.7.0/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.2 h1:ru//jj7Y5Xj9CXBpeNyWCoxjq8iT0d+a2lNeSiN9P/o=
maunium.net/go/mautrix v0.7.2/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.4 h1:MDjrvDyHcu5ozKAa80ohcXmYAXZTHgHxrhiERtvkEdY=
maunium.net/go/mautrix v0.7.4/go.mod h1:Va/74MijqaS0DQ3aUqxmFO54/PMfr1LVsCOcGRHbYmo=
maunium.net/go/mautrix v0.7.7 h1:yfpTizagog8NRHcMjxkCyY7Vreb0OEXaessaJBaLQrw=
maunium.net/go/mautrix v0.7.7/go.mod h1:FpsAvwNdG3Zeup7Y2Nlv81Lk0h6iVRPoIy6D7g/7YCE=
maunium.net/go/mautrix v0.7.8 h1:Gz4q9tqmLLN7oP+Qhu72F6uJs7QYi+lkpfpetXocjH4=
maunium.net/go/mautrix v0.7.8/go.mod h1:FpsAvwNdG3Zeup7Y2Nlv81Lk0h6iVRPoIy6D7g/7YCE=
maunium.net/go/mautrix v0.7.9 h1:WL7F8wSiq7l9zfXZXT8FvwC0PPnB7PsQeiSZel4hNwY=
maunium.net/go/mautrix v0.7.9/go.mod h1:FpsAvwNdG3Zeup7Y2Nlv81Lk0h6iVRPoIy6D7g/7YCE=
maunium.net/go/mautrix v0.7.10 h1:s9LMv0RCZBRJo653VS4xGO3Q/DbCrT2sShvDI7vR/u4=
maunium.net/go/mautrix v0.7.10/go.mod h1:FpsAvwNdG3Zeup7Y2Nlv81Lk0h6iVRPoIy6D7g/7YCE=

View file

@ -20,6 +20,7 @@ import (
"bytes"
"encoding/gob"
"encoding/hex"
"errors"
"fmt"
"html"
"image"
@ -39,7 +40,6 @@ import (
"sync"
"time"
"github.com/pkg/errors"
log "maunium.net/go/maulogger/v2"
"maunium.net/go/mautrix/crypto/attachment"
@ -1168,7 +1168,7 @@ func (portal *Portal) sendMessage(intent *appservice.IntentAPI, eventType event.
if portal.Encrypted && portal.bridge.Crypto != nil {
encrypted, err := portal.bridge.Crypto.Encrypt(portal.MXID, eventType, wrappedContent)
if err != nil {
return nil, errors.Wrap(err, "failed to encrypt event")
return nil, fmt.Errorf("failed to encrypt event: %w", err)
}
eventType = event.EventEncrypted
wrappedContent.Parsed = encrypted
@ -1424,7 +1424,7 @@ func (portal *Portal) HandleMediaMessage(source *User, msg mediaMessage) {
portal.log.Warnfln("Failed to download media for %s: %v. Calling LoadMediaInfo and retrying download...", msg.info.Id, err)
_, err = source.Conn.LoadMediaInfo(msg.info.RemoteJid, msg.info.Id, msg.info.FromMe)
if err != nil {
portal.sendMediaBridgeFailure(source, intent, msg.info, errors.Wrap(err, "failed to load media info"))
portal.sendMediaBridgeFailure(source, intent, msg.info, fmt.Errorf("failed to load media info: %w", err))
return
}
data, err = msg.download()
@ -1441,14 +1441,14 @@ func (portal *Portal) HandleMediaMessage(source *User, msg mediaMessage) {
if msg.mimeType == "image/webp" {
img, err := decodeWebp(bytes.NewReader(data))
if err != nil {
portal.sendMediaBridgeFailure(source, intent, msg.info, errors.Wrap(err, "failed to decode webp"))
portal.sendMediaBridgeFailure(source, intent, msg.info, fmt.Errorf("failed to decode webp: %w", err))
return
}
var buf bytes.Buffer
err = png.Encode(&buf, img)
if err != nil {
portal.sendMediaBridgeFailure(source, intent, msg.info, errors.Wrap(err, "failed to convert to png"))
portal.sendMediaBridgeFailure(source, intent, msg.info, fmt.Errorf("failed to convert to png: %w", err))
return
}
data = buf.Bytes()
@ -1470,7 +1470,7 @@ func (portal *Portal) HandleMediaMessage(source *User, msg mediaMessage) {
} else if httpErr := err.(mautrix.HTTPError); httpErr.IsStatus(413) {
portal.sendMediaBridgeFailure(source, intent, msg.info, errors.New("proxy rejected too large file"))
} else {
portal.sendMediaBridgeFailure(source, intent, msg.info, errors.Wrap(err, "failed to upload media"))
portal.sendMediaBridgeFailure(source, intent, msg.info, fmt.Errorf("failed to upload media: %w", err))
}
return
}
@ -1615,18 +1615,18 @@ func (portal *Portal) downloadThumbnail(content *event.MessageEventContent, id i
func (portal *Portal) convertGifToVideo(gif []byte) ([]byte, error) {
dir, err := ioutil.TempDir("", "gif-convert-*")
if err != nil {
return nil, errors.Wrap(err, "failed to make temp dir")
return nil, fmt.Errorf("failed to make temp dir: %w", err)
}
defer os.RemoveAll(dir)
inputFile, err := os.OpenFile(filepath.Join(dir, "input.gif"), os.O_CREATE|os.O_EXCL|os.O_WRONLY, 0600)
if err != nil {
return nil, errors.Wrap(err, "failed open input file")
return nil, fmt.Errorf("failed open input file: %w", err)
}
_, err = inputFile.Write(gif)
if err != nil {
_ = inputFile.Close()
return nil, errors.Wrap(err, "failed to write gif to input file")
return nil, fmt.Errorf("failed to write gif to input file: %w", err)
}
_ = inputFile.Close()
@ -1642,11 +1642,11 @@ func (portal *Portal) convertGifToVideo(gif []byte) ([]byte, error) {
err = cmd.Run()
if err != nil {
return nil, errors.Wrap(err, "failed to run ffmpeg")
return nil, fmt.Errorf("failed to run ffmpeg: %w", err)
}
outputFile, err := os.OpenFile(filepath.Join(dir, "output.mp4"), os.O_RDONLY, 0)
if err != nil {
return nil, errors.Wrap(err, "failed to open output file")
return nil, fmt.Errorf("failed to open output file: %w", err)
}
defer func() {
_ = outputFile.Close()
@ -1654,7 +1654,7 @@ func (portal *Portal) convertGifToVideo(gif []byte) ([]byte, error) {
}()
mp4, err := ioutil.ReadAll(outputFile)
if err != nil {
return nil, errors.Wrap(err, "failed to read mp4 from output file")
return nil, fmt.Errorf("failed to read mp4 from output file: %w", err)
}
return mp4, nil
}
@ -2058,7 +2058,7 @@ func (portal *Portal) Delete() {
func (portal *Portal) GetMatrixUsers() ([]id.UserID, error) {
members, err := portal.MainIntent().JoinedMembers(portal.MXID)
if err != nil {
return nil, errors.Wrap(err, "failed to get member list")
return nil, fmt.Errorf("failed to get member list: %w", err)
}
var users []id.UserID
for userID := range members.Joined {