Skip to content
Open
2 changes: 1 addition & 1 deletion rfq/negotiator.go
Original file line number Diff line number Diff line change
Expand Up @@ -513,7 +513,7 @@ func createCustomRejectErr(err error) rfqmsg.RejectErr {
// The rejection message will state that the oracle doesn't
// support the asset.
case ErrUnsupportedOracleAsset:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

in the future would we append to this switch all the cases for codes that are considered public?

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I read the iota list of all error codes I don't really have some information source as to whether they are public or internal error codes.

We could follow a convention that all non-zero codes are public (with appropriate docs in the definitions ofcs)

Or further extend the oracle error with a direct Internal bool flag, that explicitly indicates whether this code/msg should be shared or not

Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yeah I like that latter idea -- let the oracle indicate whether the error is intended to be public/private. 👍

msg := oracleError.Error()
msg := oracleError.Msg
return rfqmsg.ErrRejectWithCustomMsg(msg)

// The rejection message will be opaque, with the error
Expand Down
17 changes: 15 additions & 2 deletions rfq/oracle.go
Original file line number Diff line number Diff line change
Expand Up @@ -371,7 +371,7 @@ func (r *RpcPriceOracle) QuerySellPrice(ctx context.Context,
return &OracleResponse{
Err: &OracleError{
Msg: result.Error.Message,
Code: OracleErrorCode(result.Error.Code),
Code: marshallErrorCode(result.Error.Code),
},
}, nil

Expand All @@ -380,6 +380,19 @@ func (r *RpcPriceOracle) QuerySellPrice(ctx context.Context,
}
}

// marshallErrorCode marshalls an over-the-wire error code into an
// OracleErrorCode.
func marshallErrorCode(code oraclerpc.ErrorCode) OracleErrorCode {
switch code {
case oraclerpc.ErrorCode_ERROR_UNSPECIFIED:
return ErrUnspecifiedOracleError
case oraclerpc.ErrorCode_ERROR_UNSUPPORTED:
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

we add an empty line before a new switch case

Suggested change
case oraclerpc.ErrorCode_ERROR_UNSUPPORTED:
case oraclerpc.ErrorCode_ERROR_UNSUPPORTED:

Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

except for the first case (but including the default case below)

return ErrUnsupportedOracleAsset
default:
return ErrUnspecifiedOracleError
}
}

// QueryBuyPrice returns a buy price for the given asset amount.
func (r *RpcPriceOracle) QueryBuyPrice(ctx context.Context,
assetSpecifier asset.Specifier, assetMaxAmt fn.Option[uint64],
Expand Down Expand Up @@ -483,7 +496,7 @@ func (r *RpcPriceOracle) QueryBuyPrice(ctx context.Context,
return &OracleResponse{
Err: &OracleError{
Msg: result.Error.Message,
Code: OracleErrorCode(result.Error.Code),
Code: marshallErrorCode(result.Error.Code),
},
}, nil

Expand Down