mirror of
https://github.com/nspcc-dev/neo-go.git
synced 2025-01-03 09:22:49 +00:00
cli: fix error handling in upload-bin command
Fix shared global error reuse. Close #3634 Signed-off-by: Ekaterina Pavlova <ekt@morphbits.io>
This commit is contained in:
parent
0b79901b7f
commit
e83b3e4839
1 changed files with 29 additions and 28 deletions
|
@ -155,16 +155,17 @@ func uploadBin(ctx *cli.Context) error {
|
||||||
defer wg.Done()
|
defer wg.Done()
|
||||||
for blockIndex := batchStart + i; blockIndex < batchEnd; blockIndex += numWorkers {
|
for blockIndex := batchStart + i; blockIndex < batchEnd; blockIndex += numWorkers {
|
||||||
var blk *block.Block
|
var blk *block.Block
|
||||||
err = retry(func() error {
|
errGet := retry(func() error {
|
||||||
blk, err = rpc.GetBlockByIndex(uint32(blockIndex))
|
var errGetBlock error
|
||||||
if err != nil {
|
blk, errGetBlock = rpc.GetBlockByIndex(uint32(blockIndex))
|
||||||
return fmt.Errorf("failed to fetch block %d: %w", blockIndex, err)
|
if errGetBlock != nil {
|
||||||
|
return fmt.Errorf("failed to fetch block %d: %w", blockIndex, errGetBlock)
|
||||||
}
|
}
|
||||||
return nil
|
return nil
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errGet != nil {
|
||||||
select {
|
select {
|
||||||
case errorCh <- err:
|
case errorCh <- errGet:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -185,12 +186,12 @@ func uploadBin(ctx *cli.Context) error {
|
||||||
}
|
}
|
||||||
|
|
||||||
objBytes := bw.Bytes()
|
objBytes := bw.Bytes()
|
||||||
err = retry(func() error {
|
errRetr := retry(func() error {
|
||||||
return uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled)
|
return uploadObj(ctx.Context, p, signer, acc.PrivateKey().GetScriptHash(), containerID, objBytes, attrs, homomorphicHashingDisabled)
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errRetr != nil {
|
||||||
select {
|
select {
|
||||||
case errorCh <- err:
|
case errorCh <- errRetr:
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
return
|
return
|
||||||
|
@ -205,7 +206,7 @@ func uploadBin(ctx *cli.Context) error {
|
||||||
}()
|
}()
|
||||||
|
|
||||||
select {
|
select {
|
||||||
case err := <-errorCh:
|
case err = <-errorCh:
|
||||||
return cli.Exit(fmt.Errorf("upload error: %w", err), 1)
|
return cli.Exit(fmt.Errorf("upload error: %w", err), 1)
|
||||||
case <-doneCh:
|
case <-doneCh:
|
||||||
}
|
}
|
||||||
|
@ -315,16 +316,14 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
filters.AddFilter(attributeKey, fmt.Sprintf("%d", 0), object.MatchNumGE)
|
filters.AddFilter(attributeKey, fmt.Sprintf("%d", 0), object.MatchNumGE)
|
||||||
filters.AddFilter("IndexSize", fmt.Sprintf("%d", indexFileSize), object.MatchStringEqual)
|
filters.AddFilter("IndexSize", fmt.Sprintf("%d", indexFileSize), object.MatchStringEqual)
|
||||||
prm.SetFilters(filters)
|
prm.SetFilters(filters)
|
||||||
var (
|
var objectIDs []oid.ID
|
||||||
objectIDs []oid.ID
|
errSearch := retry(func() error {
|
||||||
err error
|
var errSearchIndex error
|
||||||
)
|
objectIDs, errSearchIndex = neofs.ObjectSearch(ctx.Context, p, account.PrivateKey(), containerID.String(), prm)
|
||||||
err = retry(func() error {
|
return errSearchIndex
|
||||||
objectIDs, err = neofs.ObjectSearch(ctx.Context, p, account.PrivateKey(), containerID.String(), prm)
|
|
||||||
return err
|
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errSearch != nil {
|
||||||
return fmt.Errorf("search of index files failed: %w", err)
|
return fmt.Errorf("search of index files failed: %w", errSearch)
|
||||||
}
|
}
|
||||||
|
|
||||||
existingIndexCount := uint(len(objectIDs))
|
existingIndexCount := uint(len(objectIDs))
|
||||||
|
@ -346,13 +345,14 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
go func() {
|
go func() {
|
||||||
for id := range oidCh {
|
for id := range oidCh {
|
||||||
var obj *object.Object
|
var obj *object.Object
|
||||||
err = retry(func() error {
|
errRetr := retry(func() error {
|
||||||
obj, err = p.ObjectHead(context.Background(), containerID, id, signer, client.PrmObjectHead{})
|
var errGetHead error
|
||||||
return err
|
obj, errGetHead = p.ObjectHead(context.Background(), containerID, id, signer, client.PrmObjectHead{})
|
||||||
|
return errGetHead
|
||||||
})
|
})
|
||||||
if err != nil {
|
if errRetr != nil {
|
||||||
select {
|
select {
|
||||||
case errCh <- fmt.Errorf("failed to fetch object %s: %w", id.String(), err):
|
case errCh <- fmt.Errorf("failed to fetch object %s: %w", id.String(), errRetr):
|
||||||
default:
|
default:
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -384,9 +384,10 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", end), object.MatchNumLT)
|
filters.AddFilter(blockAttributeKey, fmt.Sprintf("%d", end), object.MatchNumLT)
|
||||||
prm.SetFilters(filters)
|
prm.SetFilters(filters)
|
||||||
var objIDs []oid.ID
|
var objIDs []oid.ID
|
||||||
err = retry(func() error {
|
err := retry(func() error {
|
||||||
objIDs, err = neofs.ObjectSearch(ctx.Context, p, account.PrivateKey(), containerID.String(), prm)
|
var errSearchIndex error
|
||||||
return err
|
objIDs, errSearchIndex = neofs.ObjectSearch(ctx.Context, p, account.PrivateKey(), containerID.String(), prm)
|
||||||
|
return errSearchIndex
|
||||||
})
|
})
|
||||||
|
|
||||||
if err != nil {
|
if err != nil {
|
||||||
|
@ -417,7 +418,7 @@ func updateIndexFiles(ctx *cli.Context, p *pool.Pool, containerID cid.ID, accoun
|
||||||
*object.NewAttribute(attributeKey, strconv.Itoa(int(i))),
|
*object.NewAttribute(attributeKey, strconv.Itoa(int(i))),
|
||||||
*object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))),
|
*object.NewAttribute("IndexSize", strconv.Itoa(int(indexFileSize))),
|
||||||
}
|
}
|
||||||
err = uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled)
|
err := uploadObj(ctx.Context, p, signer, account.PrivateKey().GetScriptHash(), containerID, buffer, attrs, homomorphicHashingDisabled)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return fmt.Errorf("failed to upload index file %d: %w", i, err)
|
return fmt.Errorf("failed to upload index file %d: %w", i, err)
|
||||||
}
|
}
|
||||||
|
|
Loading…
Reference in a new issue