mirror of
https://github.com/anyproto/anytype-heart.git
synced 2025-06-07 21:37:04 +09:00
GO-1943: Fix remaining error wrapping (errorlint fix)
This commit is contained in:
parent
1e820cb20c
commit
0c76d0e3eb
8 changed files with 22 additions and 22 deletions
|
@ -34,17 +34,17 @@ func main() {
|
|||
func decodeFile(path string) (string, error) {
|
||||
b, err := ioutil.ReadFile(path)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to read file: %s", err)
|
||||
return "", fmt.Errorf("failed to read file: %w", err)
|
||||
}
|
||||
var snapshot pb.ChangeSnapshot
|
||||
err = proto.Unmarshal(b, &snapshot)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to unmarshal pb: %s", err)
|
||||
return "", fmt.Errorf("failed to unmarshal pb: %w", err)
|
||||
}
|
||||
marsh := &jsonpb.Marshaler{Indent: " "}
|
||||
s, err := marsh.MarshalToString(&snapshot)
|
||||
if err != nil {
|
||||
return "", fmt.Errorf("failed to marshal to json: %s", err)
|
||||
return "", fmt.Errorf("failed to marshal to json: %w", err)
|
||||
}
|
||||
|
||||
return s, nil
|
||||
|
|
|
@ -36,7 +36,7 @@ var (
|
|||
func init() {
|
||||
err := json.Unmarshal(excludedJson, &objectsToExcludeSlice)
|
||||
if err != nil {
|
||||
panic(fmt.Errorf("failed to unmarshal excluded.json: %v", err))
|
||||
panic(fmt.Errorf("failed to unmarshal excluded.json: %w", err))
|
||||
}
|
||||
objectsToExclude = make(map[string]struct{})
|
||||
for _, id := range objectsToExcludeSlice {
|
||||
|
|
|
@ -56,7 +56,7 @@ func run() error {
|
|||
|
||||
r, err := zip.OpenReader(path)
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot open zip file %s: %v", path, err)
|
||||
return fmt.Errorf("cannot open zip file %s: %w", path, err)
|
||||
}
|
||||
defer r.Close()
|
||||
|
||||
|
@ -74,7 +74,7 @@ func run() error {
|
|||
|
||||
zf, err := os.Create(pathToNewZip)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create output zip file: %v", err)
|
||||
return fmt.Errorf("failed to create output zip file: %w", err)
|
||||
}
|
||||
defer zf.Close()
|
||||
|
||||
|
@ -118,7 +118,7 @@ func processFiles(files []*zip.File, zw *zip.Writer, info *useCaseInfo) error {
|
|||
for _, f := range files {
|
||||
rd, err := f.Open()
|
||||
if err != nil {
|
||||
return fmt.Errorf("cannot open pb file %s: %v", f.Name, err)
|
||||
return fmt.Errorf("cannot open pb file %s: %w", f.Name, err)
|
||||
}
|
||||
if f.Name == anytypeProfileFilename {
|
||||
fmt.Println(anytypeProfileFilename, "is excluded")
|
||||
|
@ -135,10 +135,10 @@ func processFiles(files []*zip.File, zw *zip.Writer, info *useCaseInfo) error {
|
|||
}
|
||||
nf, err := zw.Create(f.Name)
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to create new file %s: %v", f.Name, err)
|
||||
return fmt.Errorf("failed to create new file %s: %w", f.Name, err)
|
||||
}
|
||||
if _, err = io.Copy(nf, bytes.NewReader(data)); err != nil {
|
||||
return fmt.Errorf("failed to copy snapshot to new file %s: %v", f.Name, err)
|
||||
return fmt.Errorf("failed to copy snapshot to new file %s: %w", f.Name, err)
|
||||
}
|
||||
}
|
||||
if incorrectFileFound {
|
||||
|
@ -153,7 +153,7 @@ func processFile(r io.ReadCloser, name string, info *useCaseInfo) ([]byte, error
|
|||
id := strings.TrimSuffix(name, filepath.Ext(name))
|
||||
data, err := io.ReadAll(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("cannot read data from file %s: %v", name, err)
|
||||
return nil, fmt.Errorf("cannot read data from file %s: %w", name, err)
|
||||
}
|
||||
|
||||
if name == constant.ProfileFile {
|
||||
|
@ -195,13 +195,13 @@ func extractSnapshotAndType(data []byte, name string) (s *pb.ChangeSnapshot, sbt
|
|||
snapshotWithType := &pb.SnapshotWithType{}
|
||||
sbt = model.SmartBlockType_Page
|
||||
if err = snapshotWithType.Unmarshal(data); err != nil {
|
||||
return nil, sbt, false, fmt.Errorf("cannot unmarshal snapshot from file %s: %v", name, err)
|
||||
return nil, sbt, false, fmt.Errorf("cannot unmarshal snapshot from file %s: %w", name, err)
|
||||
}
|
||||
if snapshotWithType.SbType == model.SmartBlockType_AccountOld {
|
||||
s = &pb.ChangeSnapshot{}
|
||||
isOldAccount = true
|
||||
if err = s.Unmarshal(data); err != nil {
|
||||
return nil, sbt, false, fmt.Errorf("cannot unmarshal snapshot from file %s: %v", name, err)
|
||||
return nil, sbt, false, fmt.Errorf("cannot unmarshal snapshot from file %s: %w", name, err)
|
||||
}
|
||||
} else {
|
||||
s = snapshotWithType.Snapshot
|
||||
|
@ -278,7 +278,7 @@ func processAccountRelatedDetails(s *pb.ChangeSnapshot) {
|
|||
func processProfile(data []byte, info *useCaseInfo) ([]byte, error) {
|
||||
profile := &pb.Profile{}
|
||||
if err := profile.Unmarshal(data); err != nil {
|
||||
e := fmt.Errorf("cannot unmarshal profile: %v", err)
|
||||
e := fmt.Errorf("cannot unmarshal profile: %w", err)
|
||||
fmt.Println(e)
|
||||
return nil, e
|
||||
}
|
||||
|
|
|
@ -267,7 +267,7 @@ func (g *gateway) getFile(ctx context.Context, r *http.Request) (files.File, io.
|
|||
}
|
||||
file, err := g.fileService.FileByHash(ctx, id)
|
||||
if err != nil {
|
||||
return nil, nil, fmt.Errorf("get file by hash: %s", err)
|
||||
return nil, nil, fmt.Errorf("get file by hash: %w", err)
|
||||
}
|
||||
|
||||
reader, err := file.Reader(ctx)
|
||||
|
|
|
@ -122,7 +122,7 @@ func (m *ImageResize) resizeJPEG(imgConfig *image.Config, r io.ReadSeeker) (*Res
|
|||
var exifData []byte
|
||||
exifData, err = getExifData(r)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get exif data %s", err)
|
||||
return nil, fmt.Errorf("failed to get exif data %w", err)
|
||||
}
|
||||
|
||||
_, err = r.Seek(0, io.SeekStart)
|
||||
|
@ -136,7 +136,7 @@ func (m *ImageResize) resizeJPEG(imgConfig *image.Config, r io.ReadSeeker) (*Res
|
|||
if exifData != nil {
|
||||
orientation, err = getJpegOrientation(exifData)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to get jpeg orientation: %s", err)
|
||||
return nil, fmt.Errorf("failed to get jpeg orientation: %w", err)
|
||||
}
|
||||
_, err = r.Seek(0, io.SeekStart)
|
||||
if err != nil {
|
||||
|
@ -152,7 +152,7 @@ func (m *ImageResize) resizeJPEG(imgConfig *image.Config, r io.ReadSeeker) (*Res
|
|||
|
||||
img = reverseOrientation(img, orientation)
|
||||
if err != nil {
|
||||
err = fmt.Errorf("failed to fix img orientation: %s", err)
|
||||
err = fmt.Errorf("failed to fix img orientation: %w", err)
|
||||
return nil, err
|
||||
}
|
||||
imgConfig.Width, imgConfig.Height = img.Bounds().Max.X, img.Bounds().Max.Y
|
||||
|
@ -376,7 +376,7 @@ func patchReaderRemoveExif(r io.ReadSeeker) (io.Reader, error) {
|
|||
buff := bytes.NewBuffer(make([]byte, 0, size))
|
||||
intfc, err := jmp.Parse(r, int(size))
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("failed to open file to read exif: %s", err)
|
||||
return nil, fmt.Errorf("failed to open file to read exif: %w", err)
|
||||
}
|
||||
sl := intfc.(*jpegstructure.SegmentList)
|
||||
|
||||
|
|
|
@ -157,7 +157,7 @@ func SmartblockTypeFromID(id string) (smartblock.SmartBlockType, error) {
|
|||
c, err := cid.Decode(id)
|
||||
if err != nil {
|
||||
return smartblock.SmartBlockTypePage,
|
||||
fmt.Errorf("failed to determine smartblock type, objectID: %s, err: %s", id, err)
|
||||
fmt.Errorf("failed to determine smartblock type, objectID: %s, err: %w", id, err)
|
||||
}
|
||||
// TODO: discard this fragile condition as soon as we will move to the multiaddr with prefix
|
||||
if c.Prefix().Codec == cid.DagProtobuf && c.Prefix().MhType == multihash.SHA2_256 {
|
||||
|
|
|
@ -172,7 +172,7 @@ func (b *builtinObjects) CreateObjectsForUseCase(
|
|||
|
||||
if err = b.inject(ctx, spaceID, useCase, archive); err != nil {
|
||||
return pb.RpcObjectImportUseCaseResponseError_UNKNOWN_ERROR,
|
||||
fmt.Errorf("failed to import builtinObjects for Use Case %s: %s",
|
||||
fmt.Errorf("failed to import builtinObjects for Use Case %s: %w",
|
||||
pb.RpcObjectImportUseCaseRequestUseCase_name[int32(useCase)], err)
|
||||
}
|
||||
|
||||
|
|
|
@ -38,13 +38,13 @@ func StackCompact(allGoroutines bool) string {
|
|||
func SaveStackToRepo(repoPath string, allGoroutines bool) error {
|
||||
dirPath := filepath.Join(repoPath, logsPath)
|
||||
if err := os.Mkdir(dirPath, 0777); err != nil && !os.IsExist(err) {
|
||||
return fmt.Errorf("failed to create /logs directory: %v", err)
|
||||
return fmt.Errorf("failed to create /logs directory: %w", err)
|
||||
}
|
||||
filePath := filepath.Join(dirPath, fmt.Sprintf("stack.%s.log", time.Now().Format("20060102.150405.99")))
|
||||
stack := Stack(allGoroutines)
|
||||
//nolint: gosec
|
||||
if err := os.WriteFile(filePath, stack, 0644); err != nil {
|
||||
return fmt.Errorf("failed to write stacktrace to file: %v", err)
|
||||
return fmt.Errorf("failed to write stacktrace to file: %w", err)
|
||||
}
|
||||
return nil
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue