Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Throw errors on unknown Operation parameters #272

Open
msfeldstein opened this issue Sep 12, 2019 · 10 comments
Open

Throw errors on unknown Operation parameters #272

msfeldstein opened this issue Sep 12, 2019 · 10 comments
Labels
bug Hacktoberfest suggested issues for Hacktoberfest help wanted

Comments

@msfeldstein
Copy link

Describe the bug
Currently when you're creating operations for a transaction, you can pass incorrect parameters and the sdk quietly lets you. For example

StellarSdk.Operation.changeTrust({
    amount: "0"
  })

seems to work, but the correct params are

StellarSdk.Operation.changeTrust({
    limit: "0"
  })

We should throw an error when you try to pass amount since that's clearly something wrong. It will save developers a lot of frustration to find out early that something is wrong than to have to figure out why the operation didn't do what they expected.

@ire-and-curses
Copy link
Member

We just did this in the Go SDK, for reference: stellar/go#1041

@ire-and-curses ire-and-curses changed the title Throw errors on unknown Operation paramters Throw errors on unknown Operation parameters Sep 12, 2019
@abuiles
Copy link
Contributor

abuiles commented Sep 13, 2019

@msfeldstein we have this validation in place already via TypeScript. The downside is that it won't be done if you are using plain JS which is probably your scenario. While I think we could add this validations, I'd prefer we don't and rely on the tools that we are trying to double down, in this case TS.

@msfeldstein
Copy link
Author

msfeldstein commented Sep 13, 2019 via email

@msfeldstein
Copy link
Author

msfeldstein commented Sep 13, 2019 via email

@msfeldstein
Copy link
Author

do you have any thoughts as to why my VSCode wouldn't warn on this? It usually has good typechecking

@abuiles
Copy link
Contributor

abuiles commented Sep 13, 2019

I'm not sure I agree with that, we shouldn't prescribe tooling to our users to that degree. If we do we should call this ts-stellar-sdk

You are right. I'm surprised it didn't fail for you since we have a validation in place in the code for the required fields. What was your error?

Does ts offer any way to validate at runtime?

AFAIK no, it's static.

do you have any thoughts as to why my VSCode wouldn't warn on this? It usually has good typechecking

Are you running TS? I think it will warn you on TS, but it won't in Node/Vanilla JS

@abuiles abuiles transferred this issue from stellar/js-stellar-sdk Sep 13, 2019
@abuiles
Copy link
Contributor

abuiles commented Sep 13, 2019

I transferred this issue to js-stellar-base which is where the underlying issue exists. After looking at the code, we do validate the arguments, however, we ignore extra arguments in options, this is a common pattern in JS, receive an object and take only the stuff that you need, that's how we achieve optional arguments too.

The requirement here is for the app to fail because you pass stuff which is not supposed to be in the options, I think this is a nice to have but not necessarily a bug, by looking at the documentation, it says what the params should be https://stellar.github.io/js-stellar-sdk/Operation.html#.changeTrust

Leaving it open for reference and we can fix it later.

@msfeldstein
Copy link
Author

yeah seems like a low priority feature request.

@abuiles abuiles added the Hacktoberfest suggested issues for Hacktoberfest label Oct 2, 2019
@charlie-wasp
Copy link
Contributor

@abuiles @msfeldstein is this feature request still relevant? I believe, I could take that

@abuiles
Copy link
Contributor

abuiles commented Jan 28, 2020

@charlie-wasp sure thing, please go ahead!

Btw, I dropped the ball in the ts migration, maybe we should revisit it in a couple of weeks.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Hacktoberfest suggested issues for Hacktoberfest help wanted
Projects
None yet
Development

No branches or pull requests

4 participants