system/tmpfiles: fail gracefully in API misuse
Panicking here leaves garbage behind. Not ideal if this package is going to be exported. Signed-off-by: Ophestra <cat@gensokyo.uk>
This commit is contained in:
parent
83e72c2b59
commit
db71fbe22b
@ -2,6 +2,7 @@ package system
|
||||
|
||||
import (
|
||||
"bytes"
|
||||
"errors"
|
||||
"fmt"
|
||||
"io"
|
||||
"os"
|
||||
@ -35,6 +36,11 @@ func (t *Tmpfile) Type() Enablement { return Process }
|
||||
func (t *Tmpfile) apply(_ *I) error {
|
||||
fmsg.Verbose("copying", t)
|
||||
|
||||
if t.payload == nil {
|
||||
// this is a misuse of the API; do not return an error message
|
||||
return errors.New("invalid payload")
|
||||
}
|
||||
|
||||
if b, err := os.Stat(t.src); err != nil {
|
||||
return fmsg.WrapErrorSuffix(err,
|
||||
fmt.Sprintf("cannot stat %q:", t.src))
|
||||
|
Loading…
Reference in New Issue
Block a user