File tree 3 files changed +18
-12
lines changed
3 files changed +18
-12
lines changed Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"image/jpeg"
5
6
"log"
6
7
"os"
7
8
)
8
9
9
- func exportJPEG (stitchedImage * StitchedImage ) error {
10
- log .Printf ("Creating output file %q." , * flagOutputPath )
11
- f , err := os .Create (* flagOutputPath )
10
+ func exportJPEG (stitchedImage * StitchedImage , outputPath string ) error {
11
+ log .Printf ("Creating output file %q." , outputPath )
12
+ f , err := os .Create (outputPath )
12
13
if err != nil {
13
- log . Panic ( err )
14
+ return fmt . Errorf ( "failed to create file: %w" , err )
14
15
}
15
16
defer f .Close ()
16
17
@@ -19,7 +20,7 @@ func exportJPEG(stitchedImage *StitchedImage) error {
19
20
}
20
21
21
22
if err := jpeg .Encode (f , stitchedImage , options ); err != nil {
22
- log . Panic ( err )
23
+ return fmt . Errorf ( "failed to encode image %q: %w" , outputPath , err )
23
24
}
24
25
25
26
return nil
Original file line number Diff line number Diff line change 1
1
package main
2
2
3
3
import (
4
+ "fmt"
4
5
"image/png"
5
6
"log"
6
7
"os"
7
8
)
8
9
9
- func exportPNG (stitchedImage * StitchedImage ) error {
10
- log .Printf ("Creating output file %q." , * flagOutputPath )
11
- f , err := os .Create (* flagOutputPath )
10
+ func exportPNG (stitchedImage * StitchedImage , outputPath string ) error {
11
+ log .Printf ("Creating output file %q." , outputPath )
12
+ f , err := os .Create (outputPath )
12
13
if err != nil {
13
- log . Panic ( err )
14
+ return fmt . Errorf ( "failed to create file: %w" , err )
14
15
}
15
16
defer f .Close ()
16
17
@@ -19,7 +20,7 @@ func exportPNG(stitchedImage *StitchedImage) error {
19
20
}
20
21
21
22
if err := encoder .Encode (f , stitchedImage ); err != nil {
22
- log . Panic ( err )
23
+ return fmt . Errorf ( "failed to encode image %q: %w" , outputPath , err )
23
24
}
24
25
25
26
return nil
Original file line number Diff line number Diff line change @@ -269,9 +269,13 @@ func main() {
269
269
fileExtension := strings .ToLower (filepath .Ext (* flagOutputPath ))
270
270
switch fileExtension {
271
271
case ".png" :
272
- exportPNG (stitchedImage )
272
+ if err := exportPNG (stitchedImage , * flagOutputPath ); err != nil {
273
+ log .Panicf ("Export of PNG file failed: %v" , err )
274
+ }
273
275
case ".jpg" , ".jpeg" :
274
- exportJPEG (stitchedImage )
276
+ if err := exportJPEG (stitchedImage , * flagOutputPath ); err != nil {
277
+ log .Panicf ("Export of JPEG file failed: %v" , err )
278
+ }
275
279
default :
276
280
log .Panicf ("Unknown output format %q." , fileExtension )
277
281
}
You can’t perform that action at this time.
0 commit comments