feat: upgrade golangci-lint to 1.45.2
This commit is contained in:
@ -19,6 +19,7 @@ package openid
|
||||
import (
|
||||
"context"
|
||||
"encoding/json"
|
||||
"errors"
|
||||
"math/rand"
|
||||
"net/http"
|
||||
"time"
|
||||
@ -104,12 +105,13 @@ func HandleCallback(c echo.Context) error {
|
||||
// Parse the access & ID token
|
||||
oauth2Token, err := provider.Oauth2Config.Exchange(context.Background(), cb.Code)
|
||||
if err != nil {
|
||||
if rerr, is := err.(*oauth2.RetrieveError); is {
|
||||
var rerr *oauth2.RetrieveError
|
||||
if errors.As(err, &rerr) {
|
||||
log.Error(err)
|
||||
|
||||
details := make(map[string]interface{})
|
||||
if err := json.Unmarshal(rerr.Body, &details); err != nil {
|
||||
log.Errorf("Error unmarshaling token for provider %s: %v", provider.Name, err)
|
||||
log.Errorf("Error unmarshalling token for provider %s: %v", provider.Name, err)
|
||||
return handler.HandleHTTPError(err, c)
|
||||
}
|
||||
|
||||
|
@ -35,7 +35,7 @@ import (
|
||||
func Dump(filename string) error {
|
||||
dumpFile, err := os.Create(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error opening dump file: %s", err)
|
||||
return fmt.Errorf("error opening dump file: %w", err)
|
||||
}
|
||||
defer dumpFile.Close()
|
||||
|
||||
@ -47,7 +47,7 @@ func Dump(filename string) error {
|
||||
if viper.ConfigFileUsed() != "" {
|
||||
err = writeFileToZip(viper.ConfigFileUsed(), dumpWriter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving config file: %s", err)
|
||||
return fmt.Errorf("error saving config file: %w", err)
|
||||
}
|
||||
} else {
|
||||
log.Warning("No config file found, not including one in the dump. This usually happens when environment variables are used for configuration.")
|
||||
@ -64,7 +64,7 @@ func Dump(filename string) error {
|
||||
if dotEnv != "" {
|
||||
err = utils.WriteBytesToZip(".env", []byte(dotEnv), dumpWriter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving env file: %s", err)
|
||||
return fmt.Errorf("error saving env file: %w", err)
|
||||
}
|
||||
log.Info("Dumped .env file")
|
||||
}
|
||||
@ -73,7 +73,7 @@ func Dump(filename string) error {
|
||||
log.Info("Start dumping version file...")
|
||||
err = utils.WriteBytesToZip("VERSION", []byte(version.Version), dumpWriter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving version: %s", err)
|
||||
return fmt.Errorf("error saving version: %w", err)
|
||||
}
|
||||
log.Info("Dumped version")
|
||||
|
||||
@ -81,12 +81,12 @@ func Dump(filename string) error {
|
||||
log.Info("Start dumping database...")
|
||||
data, err := db.Dump()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving database data: %s", err)
|
||||
return fmt.Errorf("error saving database data: %w", err)
|
||||
}
|
||||
for t, d := range data {
|
||||
err = utils.WriteBytesToZip("database/"+t+".json", d, dumpWriter)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error writing database table %s: %s", t, err)
|
||||
return fmt.Errorf("error writing database table %s: %w", t, err)
|
||||
}
|
||||
}
|
||||
log.Info("Dumped database")
|
||||
@ -95,7 +95,7 @@ func Dump(filename string) error {
|
||||
log.Info("Start dumping files...")
|
||||
allFiles, err := files.Dump()
|
||||
if err != nil {
|
||||
return fmt.Errorf("error saving file: %s", err)
|
||||
return fmt.Errorf("error saving file: %w", err)
|
||||
}
|
||||
|
||||
err = utils.WriteFilesToZip(allFiles, dumpWriter)
|
||||
|
@ -44,7 +44,7 @@ func Restore(filename string) error {
|
||||
|
||||
r, err := zip.OpenReader(filename)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open zip file: %s", err)
|
||||
return fmt.Errorf("could not open zip file: %w", err)
|
||||
}
|
||||
|
||||
log.Warning("Restoring a dump will wipe your current installation!")
|
||||
@ -52,7 +52,7 @@ func Restore(filename string) error {
|
||||
cr := bufio.NewReader(os.Stdin)
|
||||
text, err := cr.ReadString('\n')
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read confirmation message: %s", err)
|
||||
return fmt.Errorf("could not read confirmation message: %w", err)
|
||||
}
|
||||
if text != "Yes, I understand\n" {
|
||||
return fmt.Errorf("invalid confirmation message")
|
||||
@ -99,7 +99,7 @@ func Restore(filename string) error {
|
||||
// Restore the db
|
||||
// Start by wiping everything
|
||||
if err := db.WipeEverything(); err != nil {
|
||||
return fmt.Errorf("could not wipe database: %s", err)
|
||||
return fmt.Errorf("could not wipe database: %w", err)
|
||||
}
|
||||
log.Info("Wiped database.")
|
||||
|
||||
@ -108,18 +108,18 @@ func Restore(filename string) error {
|
||||
migrations := dbfiles["migration"]
|
||||
rc, err := migrations.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open migrations: %s", err)
|
||||
return fmt.Errorf("could not open migrations: %w", err)
|
||||
}
|
||||
defer rc.Close()
|
||||
|
||||
var buf bytes.Buffer
|
||||
if _, err := buf.ReadFrom(rc); err != nil {
|
||||
return fmt.Errorf("could not read migrations: %s", err)
|
||||
return fmt.Errorf("could not read migrations: %w", err)
|
||||
}
|
||||
|
||||
ms := []*xormigrate.Migration{}
|
||||
if err := json.Unmarshal(buf.Bytes(), &ms); err != nil {
|
||||
return fmt.Errorf("could not read migrations: %s", err)
|
||||
return fmt.Errorf("could not read migrations: %w", err)
|
||||
}
|
||||
sort.Slice(ms, func(i, j int) bool {
|
||||
return ms[i].ID > ms[j].ID
|
||||
@ -127,17 +127,17 @@ func Restore(filename string) error {
|
||||
|
||||
lastMigration := ms[len(ms)-1]
|
||||
if err := migration.MigrateTo(lastMigration.ID, nil); err != nil {
|
||||
return fmt.Errorf("could not create db structure: %s", err)
|
||||
return fmt.Errorf("could not create db structure: %w", err)
|
||||
}
|
||||
|
||||
// Restore all db data
|
||||
for table, d := range dbfiles {
|
||||
content, err := unmarshalFileToJSON(d)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not read table %s: %s", table, err)
|
||||
return fmt.Errorf("could not read table %s: %w", table, err)
|
||||
}
|
||||
if err := db.Restore(table, content); err != nil {
|
||||
return fmt.Errorf("could not restore table data for table %s: %s", table, err)
|
||||
return fmt.Errorf("could not restore table data for table %s: %w", table, err)
|
||||
}
|
||||
log.Infof("Restored table %s", table)
|
||||
}
|
||||
@ -151,18 +151,18 @@ func Restore(filename string) error {
|
||||
for i, file := range filesFiles {
|
||||
id, err := strconv.ParseInt(i, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not parse file id %s: %s", i, err)
|
||||
return fmt.Errorf("could not parse file id %s: %w", i, err)
|
||||
}
|
||||
|
||||
f := &files.File{ID: id}
|
||||
|
||||
fc, err := file.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open file %s: %s", i, err)
|
||||
return fmt.Errorf("could not open file %s: %w", i, err)
|
||||
}
|
||||
|
||||
if err := f.Save(fc); err != nil {
|
||||
return fmt.Errorf("could not save file: %s", err)
|
||||
return fmt.Errorf("could not save file: %w", err)
|
||||
}
|
||||
|
||||
_ = fc.Close()
|
||||
@ -205,7 +205,7 @@ func restoreConfig(configFile, dotEnvFile *zip.File) error {
|
||||
|
||||
outFile, err := os.OpenFile(configFile.Name, os.O_WRONLY|os.O_CREATE|os.O_TRUNC, configFile.Mode())
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open config file for writing: %s", err)
|
||||
return fmt.Errorf("could not open config file for writing: %w", err)
|
||||
}
|
||||
|
||||
cfgr, err := configFile.Open()
|
||||
@ -216,7 +216,7 @@ func restoreConfig(configFile, dotEnvFile *zip.File) error {
|
||||
// #nosec - We eliminated the potential decompression bomb by erroring out above if the file is larger than a threshold.
|
||||
_, err = io.Copy(outFile, cfgr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not create config file: %s", err)
|
||||
return fmt.Errorf("could not create config file: %w", err)
|
||||
}
|
||||
|
||||
_ = cfgr.Close()
|
||||
@ -225,7 +225,7 @@ func restoreConfig(configFile, dotEnvFile *zip.File) error {
|
||||
log.Infof("The config file has been restored to '%s'.", configFile.Name)
|
||||
log.Infof("You can now make changes to it, hit enter when you're done.")
|
||||
if _, err := bufio.NewReader(os.Stdin).ReadString('\n'); err != nil {
|
||||
return fmt.Errorf("could not read from stdin: %s", err)
|
||||
return fmt.Errorf("could not read from stdin: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
@ -249,7 +249,7 @@ func restoreConfig(configFile, dotEnvFile *zip.File) error {
|
||||
log.Warning("Make sure your current config matches the following env variables, confirm by pressing enter when done.")
|
||||
log.Warning("If your config does not match, you'll have to make the changes and restart the restoring process afterwards.")
|
||||
if _, err := bufio.NewReader(os.Stdin).ReadString('\n'); err != nil {
|
||||
return fmt.Errorf("could not read from stdin: %s", err)
|
||||
return fmt.Errorf("could not read from stdin: %w", err)
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -64,7 +64,7 @@ func (v *FileMigrator) Name() string {
|
||||
func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) error {
|
||||
r, err := zip.NewReader(file, size)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open import file: %s", err)
|
||||
return fmt.Errorf("could not open import file: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf(logPrefix+"Importing a zip file containing %d files", len(r.File))
|
||||
@ -77,7 +77,7 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
fname := strings.ReplaceAll(f.Name, "files/", "")
|
||||
id, err := strconv.ParseInt(fname, 10, 64)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not convert file id: %s", err)
|
||||
return fmt.Errorf("could not convert file id: %w", err)
|
||||
}
|
||||
storedFiles[id] = f
|
||||
log.Debugf(logPrefix + "Found a blob file")
|
||||
@ -104,18 +104,18 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
// Import the bulk of Vikunja data
|
||||
df, err := dataFile.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open data file: %s", err)
|
||||
return fmt.Errorf("could not open data file: %w", err)
|
||||
}
|
||||
defer df.Close()
|
||||
|
||||
var bufData bytes.Buffer
|
||||
if _, err := bufData.ReadFrom(df); err != nil {
|
||||
return fmt.Errorf("could not read data file: %s", err)
|
||||
return fmt.Errorf("could not read data file: %w", err)
|
||||
}
|
||||
|
||||
namespaces := []*models.NamespaceWithListsAndTasks{}
|
||||
if err := json.Unmarshal(bufData.Bytes(), &namespaces); err != nil {
|
||||
return fmt.Errorf("could not read data: %s", err)
|
||||
return fmt.Errorf("could not read data: %w", err)
|
||||
}
|
||||
|
||||
for _, n := range namespaces {
|
||||
@ -123,11 +123,11 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
if b, exists := storedFiles[l.BackgroundFileID]; exists {
|
||||
bf, err := b.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open list background file %d for reading: %s", l.BackgroundFileID, err)
|
||||
return fmt.Errorf("could not open list background file %d for reading: %w", l.BackgroundFileID, err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if _, err := buf.ReadFrom(bf); err != nil {
|
||||
return fmt.Errorf("could not read list background file %d: %s", l.BackgroundFileID, err)
|
||||
return fmt.Errorf("could not read list background file %d: %w", l.BackgroundFileID, err)
|
||||
}
|
||||
|
||||
l.BackgroundInformation = &buf
|
||||
@ -143,11 +143,11 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
for _, attachment := range t.Attachments {
|
||||
af, err := storedFiles[attachment.File.ID].Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open attachment %d for reading: %s", attachment.ID, err)
|
||||
return fmt.Errorf("could not open attachment %d for reading: %w", attachment.ID, err)
|
||||
}
|
||||
var buf bytes.Buffer
|
||||
if _, err := buf.ReadFrom(af); err != nil {
|
||||
return fmt.Errorf("could not read attachment %d: %s", attachment.ID, err)
|
||||
return fmt.Errorf("could not read attachment %d: %w", attachment.ID, err)
|
||||
}
|
||||
|
||||
attachment.ID = 0
|
||||
@ -160,7 +160,7 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
|
||||
err = migration.InsertFromStructure(namespaces, user)
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not insert data: %s", err)
|
||||
return fmt.Errorf("could not insert data: %w", err)
|
||||
}
|
||||
|
||||
if filterFile == nil {
|
||||
@ -172,18 +172,18 @@ func (v *FileMigrator) Migrate(user *user.User, file io.ReaderAt, size int64) er
|
||||
// Import filters
|
||||
ff, err := filterFile.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("could not open filters file: %s", err)
|
||||
return fmt.Errorf("could not open filters file: %w", err)
|
||||
}
|
||||
defer ff.Close()
|
||||
|
||||
var bufFilter bytes.Buffer
|
||||
if _, err := bufFilter.ReadFrom(ff); err != nil {
|
||||
return fmt.Errorf("could not read filters file: %s", err)
|
||||
return fmt.Errorf("could not read filters file: %w", err)
|
||||
}
|
||||
|
||||
filters := []*models.SavedFilter{}
|
||||
if err := json.Unmarshal(bufFilter.Bytes(), &filters); err != nil {
|
||||
return fmt.Errorf("could not read filter data: %s", err)
|
||||
return fmt.Errorf("could not read filter data: %w", err)
|
||||
}
|
||||
|
||||
log.Debugf(logPrefix+"Importing %d saved filters", len(filters))
|
||||
|
Reference in New Issue
Block a user