Skip to content

Commit f014be1

Browse files
committed
refactor TempFileCreationFailedError to be FileCreationFailedError
1 parent f12bd84 commit f014be1

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

arduino/errors.go

Lines changed: 8 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -698,21 +698,22 @@ func (e *TempDirCreationFailedError) ToRPCStatus() *status.Status {
698698
return status.New(codes.Unavailable, e.Error())
699699
}
700700

701-
// TempFileCreationFailedError is returned if a temp file could not be created
702-
type TempFileCreationFailedError struct {
703-
Cause error
701+
// FileCreationFailedError is returned if a temp file could not be created
702+
type FileCreationFailedError struct {
703+
Message string
704+
Cause error
704705
}
705706

706-
func (e *TempFileCreationFailedError) Error() string {
707-
return composeErrorMsg(tr("Cannot create temp file"), e.Cause)
707+
func (e *FileCreationFailedError) Error() string {
708+
return composeErrorMsg(e.Message, e.Cause)
708709
}
709710

710-
func (e *TempFileCreationFailedError) Unwrap() error {
711+
func (e *FileCreationFailedError) Unwrap() error {
711712
return e.Cause
712713
}
713714

714715
// ToRPCStatus converts the error into a *status.Status
715-
func (e *TempFileCreationFailedError) ToRPCStatus() *status.Status {
716+
func (e *FileCreationFailedError) ToRPCStatus() *status.Status {
716717
return status.New(codes.Unavailable, e.Error())
717718
}
718719

commands/instances.go

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -469,9 +469,9 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB Do
469469

470470
var tmp *paths.Path
471471
if tmpFile, err := ioutil.TempFile("", ""); err != nil {
472-
return nil, &arduino.TempFileCreationFailedError{Cause: err}
472+
return nil, &arduino.FileCreationFailedError{Message: tr("Cannot create temp file"), Cause: err}
473473
} else if err := tmpFile.Close(); err != nil {
474-
return nil, &arduino.TempFileCreationFailedError{Cause: err}
474+
return nil, &arduino.FileCreationFailedError{Message: tr("Cannot create temp file"), Cause: err}
475475
} else {
476476
tmp = paths.New(tmpFile.Name())
477477
}
@@ -502,9 +502,9 @@ func UpdateIndex(ctx context.Context, req *rpc.UpdateIndexRequest, downloadCB Do
502502
URLSig.Path += ".sig"
503503

504504
if t, err := ioutil.TempFile("", ""); err != nil {
505-
return nil, &arduino.TempFileCreationFailedError{Cause: err}
505+
return nil, &arduino.FileCreationFailedError{Message: tr("Cannot create temp file"), Cause: err}
506506
} else if err := t.Close(); err != nil {
507-
return nil, &arduino.TempFileCreationFailedError{Cause: err}
507+
return nil, &arduino.FileCreationFailedError{Message: tr("Cannot create temp file"), Cause: err}
508508
} else {
509509
tmpSig = paths.New(t.Name())
510510
}

0 commit comments

Comments
 (0)