cli: Add context to policy parsing errors #683

Merged
fyrchik merged 1 commit from fyrchik/frostfs-node:parsing-error into master 2023-09-12 09:47:22 +00:00

View file

@ -185,12 +185,12 @@ func parseContainerPolicy(cmd *cobra.Command, policyString string) (*netmap.Plac
return &result, nil
}
if err = result.UnmarshalJSON([]byte(policyString)); err == nil {
if err := result.UnmarshalJSON([]byte(policyString)); err == nil {
Review

It looks unnatural for Go language :)

Can you swap these lines please

if err := result.UnmarshalJSON([]byte(policyString)); err != nil {
   return nil, fmt.Errorf("can't parse placement policy: %w", err)
}

common.PrintVerbose(cmd, "Parsed JSON encoded policy")
return &result, nil
It looks unnatural for Go language :) Can you swap these lines please ```golang if err := result.UnmarshalJSON([]byte(policyString)); err != nil { return nil, fmt.Errorf("can't parse placement policy: %w", err) } common.PrintVerbose(cmd, "Parsed JSON encoded policy") return &result, nil ```
Review

It will become incorrect then -- we intentionally return an error from DecodeString

It will become incorrect then -- we intentionally return an error from `DecodeString`
Review

ah, ok

ah, ok
common.PrintVerbose(cmd, "Parsed JSON encoded policy")
return &result, nil
}
return nil, errors.New("can't parse placement policy")
return nil, fmt.Errorf("can't parse placement policy: %w", err)
}
func parseAttributes(dst *container.Container, attributes []string) error {