mirror of
https://github.com/edgelesssys/constellation.git
synced 2025-09-22 22:14:43 -04:00
AB#2033 Remove redundant "failed" in error wrapping
Remove "failed" from wrapped errors Where appropriate rephrase "unable to/could not" to "failed" in root errors Start error log messages with "Failed"
This commit is contained in:
parent
0c9ca50be8
commit
9441e46e4b
56 changed files with 204 additions and 204 deletions
|
@ -42,7 +42,7 @@ func runDeploy(cmd *cobra.Command, args []string) error {
|
|||
}
|
||||
configName, err := cmd.Flags().GetString("config")
|
||||
if err != nil {
|
||||
return err
|
||||
return fmt.Errorf("parsing config path argument: %w", err)
|
||||
}
|
||||
fileHandler := file.NewHandler(afero.NewOsFs())
|
||||
debugConfig, err := config.FromFile(fileHandler, debugConfigName)
|
||||
|
@ -78,9 +78,9 @@ func deploy(cmd *cobra.Command, fileHandler file.Handler, constellationConfig *c
|
|||
err := fileHandler.ReadJSON(constants.StateFilename, &stat)
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
log.Println("Unable to load statefile. Maybe you forgot to run \"constellation create ...\" first?")
|
||||
return fmt.Errorf("loading statefile failed: %w", err)
|
||||
return fmt.Errorf("loading statefile: %w", err)
|
||||
} else if err != nil {
|
||||
return fmt.Errorf("loading statefile failed: %w", err)
|
||||
return fmt.Errorf("loading statefile: %w", err)
|
||||
}
|
||||
ips, err = getIPsFromConfig(stat, *constellationConfig)
|
||||
if err != nil {
|
||||
|
@ -119,7 +119,7 @@ func deployOnEndpoint(ctx context.Context, in deployOnEndpointInput) error {
|
|||
defer cancel()
|
||||
conn, err := grpc.DialContext(dialCTX, in.debugdEndpoint, grpc.WithTransportCredentials(insecure.NewCredentials()))
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to other instance via gRPC: %w", err)
|
||||
return fmt.Errorf("connecting to other instance via gRPC: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
client := pb.NewDebugdClient(conn)
|
||||
|
@ -155,13 +155,13 @@ func deployOnEndpoint(ctx context.Context, in deployOnEndpointInput) error {
|
|||
|
||||
stream, err := client.UploadCoordinator(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("starting coordinator upload to instance %v failed: %w", in.debugdEndpoint, err)
|
||||
return fmt.Errorf("starting coordinator upload to instance %v: %w", in.debugdEndpoint, err)
|
||||
}
|
||||
streamErr := in.reader.ReadStream(in.coordinatorPath, stream, debugd.Chunksize, true)
|
||||
|
||||
uploadResponse, closeErr := stream.CloseAndRecv()
|
||||
if closeErr != nil {
|
||||
return fmt.Errorf("closing upload stream after uploading coordinator to %v failed: %w", in.debugdEndpoint, closeErr)
|
||||
return fmt.Errorf("closing upload stream after uploading coordinator to %v: %w", in.debugdEndpoint, closeErr)
|
||||
}
|
||||
if uploadResponse.Status == pb.UploadCoordinatorStatus_UPLOAD_COORDINATOR_FILE_EXISTS {
|
||||
log.Println("Coordinator was already uploaded")
|
||||
|
|
|
@ -27,9 +27,9 @@ func FromFile(fileHandler file.Handler, name string) (*CDBGConfig, error) {
|
|||
conf := &CDBGConfig{}
|
||||
if err := fileHandler.ReadYAML(name, conf); err != nil {
|
||||
if errors.Is(err, fs.ErrNotExist) {
|
||||
return nil, fmt.Errorf("unable to find %s - consult the README on how to setup cdbg", name)
|
||||
return nil, fmt.Errorf("%s not found - consult the README on how to setup cdbg", name)
|
||||
}
|
||||
return nil, fmt.Errorf("could not load config from file %s: %w", name, err)
|
||||
return nil, fmt.Errorf("loading config from file %s: %w", name, err)
|
||||
}
|
||||
return conf, nil
|
||||
}
|
||||
|
|
|
@ -41,14 +41,14 @@ func (f *FileStreamer) WriteStream(filename string, stream ReadChunkStream, show
|
|||
// try to read from stream once before acquiring write lock
|
||||
chunk, err := stream.Recv()
|
||||
if err != nil {
|
||||
return fmt.Errorf("reading stream failed: %w", err)
|
||||
return fmt.Errorf("reading stream: %w", err)
|
||||
}
|
||||
|
||||
f.mux.Lock()
|
||||
defer f.mux.Unlock()
|
||||
file, err := f.fs.OpenFile(filename, os.O_WRONLY|os.O_CREATE|os.O_EXCL, 0o755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open %v for writing failed: %w", filename, err)
|
||||
return fmt.Errorf("open %v for writing: %w", filename, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -70,12 +70,12 @@ func (f *FileStreamer) WriteStream(filename string, stream ReadChunkStream, show
|
|||
}
|
||||
_ = file.Close()
|
||||
_ = f.fs.Remove(filename)
|
||||
return fmt.Errorf("reading stream failed: %w", err)
|
||||
return fmt.Errorf("reading stream: %w", err)
|
||||
}
|
||||
if _, err := file.Write(chunk.Content); err != nil {
|
||||
_ = file.Close()
|
||||
_ = f.fs.Remove(filename)
|
||||
return fmt.Errorf("writing chunk to disk failed: %w", err)
|
||||
return fmt.Errorf("writing chunk to disk: %w", err)
|
||||
}
|
||||
if showProgress {
|
||||
_ = bar.Add(len(chunk.Content))
|
||||
|
@ -99,7 +99,7 @@ func (f *FileStreamer) ReadStream(filename string, stream WriteChunkStream, chun
|
|||
}
|
||||
file, err := f.fs.OpenFile(filename, os.O_RDONLY, 0o755)
|
||||
if err != nil {
|
||||
return fmt.Errorf("open %v for reading failed: %w", filename, err)
|
||||
return fmt.Errorf("open %v for reading: %w", filename, err)
|
||||
}
|
||||
defer file.Close()
|
||||
|
||||
|
@ -107,7 +107,7 @@ func (f *FileStreamer) ReadStream(filename string, stream WriteChunkStream, chun
|
|||
if showProgress {
|
||||
stat, err := file.Stat()
|
||||
if err != nil {
|
||||
return fmt.Errorf("performing stat on %v to get the file size failed: %w", filename, err)
|
||||
return fmt.Errorf("performing stat on %v to get the file size: %w", filename, err)
|
||||
}
|
||||
bar = progressbar.NewOptions64(
|
||||
stat.Size(),
|
||||
|
@ -125,11 +125,11 @@ func (f *FileStreamer) ReadStream(filename string, stream WriteChunkStream, chun
|
|||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("reading file chunk failed: %w", err)
|
||||
return fmt.Errorf("reading file chunk: %w", err)
|
||||
}
|
||||
|
||||
if err = stream.Send(&pb.Chunk{Content: buf[:n]}); err != nil {
|
||||
return fmt.Errorf("sending chunk failed: %w", err)
|
||||
return fmt.Errorf("sending chunk: %w", err)
|
||||
}
|
||||
if showProgress {
|
||||
_ = bar.Add(n)
|
||||
|
|
|
@ -43,17 +43,17 @@ func (d *Download) DownloadCoordinator(ctx context.Context, ip string) error {
|
|||
d.attemptedDownloads[serverAddr] = time.Now()
|
||||
conn, err := d.dial(ctx, serverAddr)
|
||||
if err != nil {
|
||||
return fmt.Errorf("error connecting to other instance via gRPC: %w", err)
|
||||
return fmt.Errorf("connecting to other instance via gRPC: %w", err)
|
||||
}
|
||||
defer conn.Close()
|
||||
client := pb.NewDebugdClient(conn)
|
||||
|
||||
stream, err := client.DownloadCoordinator(ctx, &pb.DownloadCoordinatorRequest{})
|
||||
if err != nil {
|
||||
return fmt.Errorf("starting coordinator download from other instance failed: %w", err)
|
||||
return fmt.Errorf("starting coordinator download from other instance: %w", err)
|
||||
}
|
||||
if err := d.writer.WriteStream(debugd.CoordinatorDeployFilename, stream, true); err != nil {
|
||||
return fmt.Errorf("streaming coordinator from other instance failed: %w", err)
|
||||
return fmt.Errorf("streaming coordinator from other instance: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("Successfully downloaded coordinator from %s\n", ip)
|
||||
|
@ -64,7 +64,7 @@ func (d *Download) DownloadCoordinator(ctx context.Context, ip string) error {
|
|||
Action: Restart,
|
||||
}
|
||||
if err := d.serviceManager.SystemdAction(ctx, restartAction); err != nil {
|
||||
return fmt.Errorf("restarting coordinator failed: %w", err)
|
||||
return fmt.Errorf("restarting coordinator: %w", err)
|
||||
}
|
||||
|
||||
return nil
|
||||
|
|
|
@ -157,7 +157,7 @@ func (f *fakeStreamToFileWriter) WriteStream(filename string, stream coordinator
|
|||
if errors.Is(err, io.EOF) {
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("reading stream failed: %w", err)
|
||||
return fmt.Errorf("reading stream: %w", err)
|
||||
}
|
||||
f.chunks = append(f.chunks, chunk.Content)
|
||||
}
|
||||
|
@ -173,7 +173,7 @@ type fakeOnlyDownloadServer struct {
|
|||
func (f *fakeOnlyDownloadServer) DownloadCoordinator(request *pb.DownloadCoordinatorRequest, stream pb.Debugd_DownloadCoordinatorServer) error {
|
||||
for _, chunk := range f.chunks {
|
||||
if err := stream.Send(&pb.Chunk{Content: chunk}); err != nil {
|
||||
return fmt.Errorf("sending chunk failed: %w", err)
|
||||
return fmt.Errorf("sending chunk: %w", err)
|
||||
}
|
||||
}
|
||||
return f.downladErr
|
||||
|
|
|
@ -80,7 +80,7 @@ type dbusConn interface {
|
|||
func (s *ServiceManager) SystemdAction(ctx context.Context, request ServiceManagerRequest) error {
|
||||
conn, err := s.dbus.NewSystemdConnectionContext(ctx)
|
||||
if err != nil {
|
||||
return fmt.Errorf("establishing systemd connection failed: %w", err)
|
||||
return fmt.Errorf("establishing systemd connection: %w", err)
|
||||
}
|
||||
|
||||
resultChan := make(chan string)
|
||||
|
@ -97,7 +97,7 @@ func (s *ServiceManager) SystemdAction(ctx context.Context, request ServiceManag
|
|||
return errors.New("unknown systemd action: " + request.Action.String())
|
||||
}
|
||||
if err != nil {
|
||||
return fmt.Errorf("failed to perform systemd action %v on unit %v: %w", request.Action, request.Unit, err)
|
||||
return fmt.Errorf("performing systemd action %v on unit %v: %w", request.Action, request.Unit, err)
|
||||
}
|
||||
|
||||
if request.Action == Reload {
|
||||
|
@ -124,11 +124,11 @@ func (s *ServiceManager) WriteSystemdUnitFile(ctx context.Context, unit SystemdU
|
|||
s.systemdUnitFilewriteLock.Lock()
|
||||
defer s.systemdUnitFilewriteLock.Unlock()
|
||||
if err := afero.WriteFile(s.fs, fmt.Sprintf("%s/%s", systemdUnitFolder, unit.Name), []byte(unit.Contents), 0o644); err != nil {
|
||||
return fmt.Errorf("writing systemd unit file \"%v\" failed: %w", unit.Name, err)
|
||||
return fmt.Errorf("writing systemd unit file \"%v\": %w", unit.Name, err)
|
||||
}
|
||||
|
||||
if err := s.SystemdAction(ctx, ServiceManagerRequest{Unit: unit.Name, Action: Reload}); err != nil {
|
||||
return fmt.Errorf("performing systemd daemon-reload failed: %w", err)
|
||||
return fmt.Errorf("performing systemd daemon-reload: %w", err)
|
||||
}
|
||||
|
||||
log.Printf("Wrote systemd unit file: %s/%s and performed daemon-reload\n", systemdUnitFolder, unit.Name)
|
||||
|
@ -142,7 +142,7 @@ func DeployDefaultServiceUnit(ctx context.Context, serviceManager *ServiceManage
|
|||
Name: debugd.CoordinatorSystemdUnitName,
|
||||
Contents: debugd.CoordinatorSystemdUnitContents,
|
||||
}); err != nil {
|
||||
return fmt.Errorf("writing systemd unit file %q failed: %w", debugd.CoordinatorSystemdUnitName, err)
|
||||
return fmt.Errorf("writing systemd unit file %q: %w", debugd.CoordinatorSystemdUnitName, err)
|
||||
}
|
||||
|
||||
// try to start the default service if the binary exists but ignore failure.
|
||||
|
|
|
@ -51,11 +51,11 @@ func NewAzure(ctx context.Context) (*Fetcher, error) {
|
|||
func (f *Fetcher) DiscoverDebugdIPs(ctx context.Context) ([]string, error) {
|
||||
self, err := f.metaAPI.Self(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieving own instance failed: %w", err)
|
||||
return nil, fmt.Errorf("retrieving own instance: %w", err)
|
||||
}
|
||||
instances, err := f.metaAPI.List(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieving instances failed: %w", err)
|
||||
return nil, fmt.Errorf("retrieving instances: %w", err)
|
||||
}
|
||||
// filter own instance from instance list
|
||||
for i, instance := range instances {
|
||||
|
@ -75,7 +75,7 @@ func (f *Fetcher) DiscoverDebugdIPs(ctx context.Context) ([]string, error) {
|
|||
func (f *Fetcher) FetchSSHKeys(ctx context.Context) ([]ssh.UserKey, error) {
|
||||
self, err := f.metaAPI.Self(ctx)
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("retrieving ssh keys from cloud provider metadata failed: %w", err)
|
||||
return nil, fmt.Errorf("retrieving ssh keys from cloud provider metadata: %w", err)
|
||||
}
|
||||
|
||||
keys := []ssh.UserKey{}
|
||||
|
|
|
@ -77,7 +77,7 @@ func (s *debugdServer) UploadCoordinator(stream pb.Debugd_UploadCoordinatorServe
|
|||
}
|
||||
log.Printf("Uploading coordinator failed: %v\n", err)
|
||||
responseStatus = pb.UploadCoordinatorStatus_UPLOAD_COORDINATOR_UPLOAD_FAILED
|
||||
return fmt.Errorf("uploading coordinator failed: %w", err)
|
||||
return fmt.Errorf("uploading coordinator: %w", err)
|
||||
}
|
||||
|
||||
log.Println("Successfully uploaded coordinator")
|
||||
|
@ -110,7 +110,7 @@ func Start(wg *sync.WaitGroup, serv pb.DebugdServer) {
|
|||
pb.RegisterDebugdServer(grpcServer, serv)
|
||||
lis, err := net.Listen("tcp", net.JoinHostPort("0.0.0.0", debugd.DebugdPort))
|
||||
if err != nil {
|
||||
log.Fatalf("failed to listen: %v", err)
|
||||
log.Fatalf("listening failed: %v", err)
|
||||
}
|
||||
log.Println("gRPC server is waiting for connections")
|
||||
grpcServer.Serve(lis)
|
||||
|
|
|
@ -381,7 +381,7 @@ func (f *fakeStreamer) WriteStream(filename string, stream coordinator.ReadChunk
|
|||
if errors.Is(err, io.EOF) {
|
||||
return f.writeStreamErr
|
||||
}
|
||||
return fmt.Errorf("reading stream failed: %w", err)
|
||||
return fmt.Errorf("reading stream: %w", err)
|
||||
}
|
||||
f.writeStreamChunks = append(f.writeStreamChunks, chunk.Content)
|
||||
}
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue