Compare commits

...

2 Commits

Author SHA1 Message Date
Eric 00104e5dff
Merge bd75928227 into 11eaebfd77 2024-06-27 15:17:51 +00:00
gmega bd75928227
Make error message for "dataset too small" more informative. 2024-06-27 12:17:44 -03:00
2 changed files with 11 additions and 4 deletions

View File

@ -85,6 +85,10 @@ type
ErasureError* = object of CodexError ErasureError* = object of CodexError
InsufficientBlocksError* = object of ErasureError InsufficientBlocksError* = object of ErasureError
# Minimum size, in bytes, that the dataset must have had
# for the encoding request to have succeeded with the parameters
# provided.
minSize*: NBytes
func indexToPos(steps, idx, step: int): int {.inline.} = func indexToPos(steps, idx, step: int): int {.inline.} =
## Convert an index to a position in the encoded ## Convert an index to a position in the encoded
@ -240,11 +244,12 @@ proc init*(
ecK: Natural, ecM: Natural, ecK: Natural, ecM: Natural,
strategy: StrategyType): ?!EncodingParams = strategy: StrategyType): ?!EncodingParams =
if ecK > manifest.blocksCount: if ecK > manifest.blocksCount:
let exc = newException(InsufficientBlocksError, let exc = (ref InsufficientBlocksError)(
"Unable to encode manifest, not enough blocks, ecK = " & msg: "Unable to encode manifest, not enough blocks, ecK = " &
$ecK & $ecK &
", blocksCount = " & ", blocksCount = " &
$manifest.blocksCount) $manifest.blocksCount,
minSize: ecK.NBytes * manifest.blockSize)
return failure(exc) return failure(exc)
let let

View File

@ -461,7 +461,9 @@ proc initPurchasingApi(node: CodexNodeRef, router: var RestRouter) =
expiry), error: expiry), error:
if error of InsufficientBlocksError: if error of InsufficientBlocksError:
return RestApiResponse.error(Http400, "Insufficient blocks, increased dataset size required") return RestApiResponse.error(Http400,
"Dataset too small for erasure parameters, need at least " &
$(ref InsufficientBlocksError)(error).minSize.int & " bytes")
return RestApiResponse.error(Http500, error.msg) return RestApiResponse.error(Http500, error.msg)