Skip to content
This repository has been archived by the owner on Oct 19, 2023. It is now read-only.

Commit

Permalink
attempt to detect errors during file writing
Browse files Browse the repository at this point in the history
  • Loading branch information
maddyblue committed Sep 7, 2017
1 parent 02a2d6a commit 2852de6
Showing 1 changed file with 14 additions and 8 deletions.
22 changes: 14 additions & 8 deletions embed/embed.go
Original file line number Diff line number Diff line change
Expand Up @@ -124,13 +124,7 @@ func Run(conf *Config) error {
}
}
sort.Strings(fnames)
w := os.Stdout
if conf.OutputFile != "" {
if w, err = os.Create(conf.OutputFile); err != nil {
return err
}
defer w.Close()
}
w := new(bytes.Buffer)
headerText, err := header(conf.Package, !(conf.Private))
if nil != err {
return fmt.Errorf("failed to expand autogenerated code: %s", err)
Expand Down Expand Up @@ -191,7 +185,19 @@ func Run(conf *Config) error {
local: %q,
},%s`, dir, local, "\n")
}
fmt.Fprint(w, footer)
w.WriteString(footer)
out := os.Stdout
if conf.OutputFile != "" {
if out, err = os.Create(conf.OutputFile); err != nil {
return err
}
}
if _, err := w.WriteTo(out); err != nil {
return err
}
if conf.OutputFile != "" {
return out.Close()
}
return nil
}

Expand Down

0 comments on commit 2852de6

Please sign in to comment.