From 7edd326b9529d2847094aeabe15c9c566b0915e5 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 21:47:10 +0100 Subject: [PATCH 1/6] fix #59: processDir should call processFile instead. --- cmd/um/main.go | 8 +------- 1 file changed, 1 insertion(+), 7 deletions(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index e6f69de..1730f38 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -236,13 +236,7 @@ func (p *processor) processDir(inputDir string) error { } filePath := filepath.Join(inputDir, item.Name()) - allDec := common.GetDecoder(filePath, p.skipNoopDecoder) - if len(allDec) == 0 { - logger.Info("skipping while no suitable decoder", zap.String("source", item.Name())) - continue - } - - if err := p.process(filePath, allDec); err != nil { + if err := p.processFile(filePath); err != nil { logger.Error("conversion failed", zap.String("source", item.Name()), zap.Error(err)) } } From 91855f8f5ba4147adcceffb2d008a05b17d64f9a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 21:52:17 +0100 Subject: [PATCH 2/6] fix #99: default output dir to where the input file is --- cmd/um/main.go | 31 ++++++++++++++++--------------- 1 file changed, 16 insertions(+), 15 deletions(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index 1730f38..aa2cccd 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -8,6 +8,7 @@ import ( "io" "os" "os/signal" + "path" "path/filepath" "runtime" "runtime/debug" @@ -84,6 +85,11 @@ func printSupportedExtensions() { } func appMain(c *cli.Context) (err error) { + cwd, err := os.Getwd() + if err != nil { + return err + } + if c.Bool("supported-ext") { printSupportedExtensions() return nil @@ -92,10 +98,7 @@ func appMain(c *cli.Context) (err error) { if input == "" { switch c.Args().Len() { case 0: - input, err = os.Getwd() - if err != nil { - return err - } + input = cwd case 1: input = c.Args().Get(0) default: @@ -104,22 +107,20 @@ func appMain(c *cli.Context) (err error) { } output := c.String("output") - if output == "" { - var err error - output, err = os.Getwd() - if err != nil { - return err - } - if input == output { - return errors.New("input and output path are same") - } - } - inputStat, err := os.Stat(input) if err != nil { return err } + if output == "" { + // Default to where the input is + if inputStat.IsDir() { + output = input + } else { + output = path.Dir(input) + } + } + outputStat, err := os.Stat(output) if err != nil { if errors.Is(err, os.ErrNotExist) { From 8b59bc026dcb7bd4b4dfbed32497d62951b68120 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 21:59:19 +0100 Subject: [PATCH 3/6] chore: ignore exe files --- .gitignore | 1 + 1 file changed, 1 insertion(+) diff --git a/.gitignore b/.gitignore index d5502c4..5c791c2 100644 --- a/.gitignore +++ b/.gitignore @@ -1,3 +1,4 @@ .idea /dist +*.exe From 2abdd47c9ca2a60869c7b1c81c57de6e7881e685 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 21:59:27 +0100 Subject: [PATCH 4/6] fix: typo --- cmd/um/main.go | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index aa2cccd..727c81c 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -151,8 +151,8 @@ func appMain(c *cli.Context) (err error) { } if inputStat.IsDir() { - wacthDir := c.Bool("watch") - if !wacthDir { + watchDir := c.Bool("watch") + if !watchDir { return proc.processDir(input) } else { return proc.watchDir(input) From 2afc232eb151f8813b5d8e047e3205e858574b1f Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 21:59:47 +0100 Subject: [PATCH 5/6] fix: don't force exit when `processFile` fails. --- cmd/um/main.go | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/cmd/um/main.go b/cmd/um/main.go index 727c81c..8f1f485 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -247,7 +247,7 @@ func (p *processor) processDir(inputDir string) error { func (p *processor) processFile(filePath string) error { allDec := common.GetDecoder(filePath, p.skipNoopDecoder) if len(allDec) == 0 { - logger.Fatal("skipping while no suitable decoder") + return errors.New("skipping while no suitable decoder") } if err := p.process(filePath, allDec); err != nil { From 36df203bdd923b8ddca9b68c2bc9b3329cd4fd44 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E9=B2=81=E6=A0=91=E4=BA=BA?= Date: Tue, 8 Oct 2024 22:01:36 +0100 Subject: [PATCH 6/6] fix: record last error when calling `processDir` --- cmd/um/main.go | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/cmd/um/main.go b/cmd/um/main.go index 8f1f485..448afc8 100644 --- a/cmd/um/main.go +++ b/cmd/um/main.go @@ -231,6 +231,8 @@ func (p *processor) processDir(inputDir string) error { if err != nil { return err } + + var lastError error = nil for _, item := range items { if item.IsDir() { continue @@ -238,9 +240,13 @@ func (p *processor) processDir(inputDir string) error { filePath := filepath.Join(inputDir, item.Name()) if err := p.processFile(filePath); err != nil { + lastError = err logger.Error("conversion failed", zap.String("source", item.Name()), zap.Error(err)) } } + if lastError != nil { + return fmt.Errorf("last error: %w", lastError) + } return nil }