Skip to content

Commit

Permalink
update error messages for create
Browse files Browse the repository at this point in the history
  • Loading branch information
konoui committed Dec 12, 2024
1 parent abb8ab1 commit 1380e84
Show file tree
Hide file tree
Showing 5 changed files with 40 additions and 3 deletions.
2 changes: 1 addition & 1 deletion Makefile
Original file line number Diff line number Diff line change
Expand Up @@ -4,7 +4,7 @@ SRC_DIR := ./
BIN_NAME := lipo
BINARY := bin/$(BIN_NAME)

GOLANGCI_LINT_VERSION := v1.58.1
GOLANGCI_LINT_VERSION := v1.62.2
export GO111MODULE=on

CMD_PACKAGE := github.com/konoui/lipo/cmd
Expand Down
2 changes: 1 addition & 1 deletion go.mod
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
module github.com/konoui/lipo

go 1.22
go 1.23

require github.com/konoui/go-qsort v0.1.0
4 changes: 4 additions & 0 deletions pkg/lipo/arch.go
Original file line number Diff line number Diff line change
Expand Up @@ -106,6 +106,10 @@ func OpenArches(inputs []*ArchInput) ([]Arch, error) {
sr := io.NewSectionReader(f, 0, stats.Size())
obj, err := lmacho.NewArch(sr)
if err != nil {
fe := &lmacho.FormatError{}
if errors.As(err, &fe) {
return nil, fmt.Errorf("can't figure out the architecture type of: %s", input.Bin)
}
return nil, err
}

Expand Down
31 changes: 30 additions & 1 deletion pkg/lipo/create_test.go
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
package lipo_test

import (
"os"
"path/filepath"
"strings"
"testing"
Expand Down Expand Up @@ -110,6 +111,34 @@ func TestLipo_CreateWithArch(t *testing.T) {
})
}

func TestLipo_CreateNonMachoFile(t *testing.T) {
tmp, err := os.CreateTemp(os.TempDir(), "dummy")
if err != nil {
t.Fatal(err.Error())
}
input := tmp.Name()
_, err = tmp.WriteString("dummydummy")
if err != nil {
t.Fatal(err)
}
tmp.Close()

l := lipo.New(
lipo.WithInputs(input),
lipo.WithOutput("dummy"),
)

err = l.Create()
if err == nil {
t.Fatal("an error does not occur")
}

want := "can't figure out the architecture type of:"
if !strings.Contains(err.Error(), want) {
t.Fatalf("want: %s, got: %s", want, err.Error())
}
}

func TestLipo_CreateError(t *testing.T) {
tests := []struct {
name string
Expand Down Expand Up @@ -152,7 +181,7 @@ func TestLipo_CreateError(t *testing.T) {
lipo.WithSegAlign(tt.segAligns...))
err := l.Create()
if err == nil {
t.Fatal("error not occur")
t.Fatal("an error does not occur")
}
if !strings.Contains(err.Error(), tt.wantErrMsg) {
t.Fatalf("want: %s, got: %s", tt.wantErrMsg, err.Error())
Expand Down
4 changes: 4 additions & 0 deletions pkg/lmacho/fat.go
Original file line number Diff line number Diff line change
Expand Up @@ -177,6 +177,10 @@ func NewFatFile(ra io.ReaderAt) (*FatFile, error) {
func NewArch(sr *io.SectionReader) (*Arch, error) {
mf, err := macho.NewFile(sr)
if err != nil {
fe := &macho.FormatError{}
if errors.As(err, &fe) {
return nil, &FormatError{Err: err}
}
return nil, err
}

Expand Down

0 comments on commit 1380e84

Please sign in to comment.