Skip to content

Commit

Permalink
fix: few bugs with error shadowing (#1737)
Browse files Browse the repository at this point in the history
Signed-off-by: Maksim An <maksiman@microsoft.com>
  • Loading branch information
anmaxvl committed Apr 26, 2023
1 parent d816cbe commit c150662
Show file tree
Hide file tree
Showing 2 changed files with 10 additions and 8 deletions.
6 changes: 4 additions & 2 deletions internal/guest/runtime/hcsv2/uvm.go
Original file line number Diff line number Diff line change
Expand Up @@ -543,7 +543,8 @@ func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *
case guestresource.ResourceTypeMappedVirtualDisk:
mvd := req.Settings.(*guestresource.LCOWMappedVirtualDisk)
// find the actual controller number on the bus and update the incoming request.
cNum, err := scsi.ActualControllerNumber(ctx, mvd.Controller)
var cNum uint8
cNum, err = scsi.ActualControllerNumber(ctx, mvd.Controller)
if err != nil {
return err
}
Expand All @@ -552,7 +553,8 @@ func (h *Host) modifyHostSettings(ctx context.Context, containerID string, req *
if !mvd.ReadOnly {
localCtx, cancel := context.WithTimeout(ctx, time.Second*5)
defer cancel()
source, err := scsi.ControllerLunToName(localCtx, mvd.Controller, mvd.Lun)
var source string
source, err = scsi.ControllerLunToName(localCtx, mvd.Controller, mvd.Lun)
if err != nil {
return err
}
Expand Down
12 changes: 6 additions & 6 deletions internal/uvm/create_lcow.go
Original file line number Diff line number Diff line change
Expand Up @@ -610,14 +610,14 @@ func makeLCOWDoc(ctx context.Context, opts *OptionsLCOW, uvm *UtilityVM) (_ *hcs
pmem := newPackedVPMemDevice()
pmem.maxMappedDeviceCount = 1

st, err := os.Stat(rootfsFullPath)
if err != nil {
return nil, errors.Wrapf(err, "failed to stat rootfs: %q", rootfsFullPath)
st, stErr := os.Stat(rootfsFullPath)
if stErr != nil {
return nil, errors.Wrapf(stErr, "failed to stat rootfs: %q", rootfsFullPath)
}
devSize := pageAlign(uint64(st.Size()))
memReg, err := pmem.Allocate(devSize)
if err != nil {
return nil, errors.Wrap(err, "failed to allocate memory for rootfs")
memReg, pErr := pmem.Allocate(devSize)
if pErr != nil {
return nil, errors.Wrap(pErr, "failed to allocate memory for rootfs")
}
defer func() {
if err != nil {
Expand Down

0 comments on commit c150662

Please sign in to comment.