File: status.go

package info (click to toggle)
vagrant 2.3.7%2Bgit20230731.5fc64cde%2Bdfsg-3
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 17,616 kB
  • sloc: ruby: 111,820; sh: 462; makefile: 123; ansic: 34; lisp: 1
file content (37 lines) | stat: -rw-r--r-- 1,036 bytes parent folder | download | duplicates (3)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
package server

import (
	"google.golang.org/grpc/codes"
	"google.golang.org/grpc/status"
	"google.golang.org/protobuf/types/known/timestamppb"

	"github.com/hashicorp/vagrant/internal/server/proto/vagrant_server"
)

// NewStatus returns a new Status message with the given initial state.
func NewStatus(init vagrant_server.Status_State) *vagrant_server.Status {
	return &vagrant_server.Status{
		State:     init,
		StartTime: timestamppb.Now(),
	}
}

// StatusSetError sets the error state on the status and marks the
// completion time.
func StatusSetError(s *vagrant_server.Status, err error) {
	st, ok := status.FromError(err)
	if !ok {
		st = status.Newf(codes.Internal, "Non-status error %T: %s", err, err)
	}

	s.State = vagrant_server.Status_ERROR
	s.Error = st.Proto()
	s.CompleteTime = timestamppb.Now()
}

// StatusSetSuccess sets state of the status to success and marks the
// completion time.
func StatusSetSuccess(s *vagrant_server.Status) {
	s.State = vagrant_server.Status_SUCCESS
	s.CompleteTime = timestamppb.Now()
}