project-serum / swap

Swap on the Serum Order Book
Apache License 2.0
78 stars 90 forks source link

Provide better error when a token account isn't created. #7

Open armaniferrante opened 3 years ago

armaniferrante commented 3 years ago

When the program is given a token account that hasn't been initialized (i.e. its data array is zero) the program ungracefully fails. For example,

Program failed to complete 
    Program 11111111111111111111111111111111 invoke [1]
    Program 11111111111111111111111111111111 success
    Program 22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD invoke [1]
    Program log: libstd rust_begin_panic
    Program log: panicked at 'range end index 32 out of range for slice of length 0', /home/armaniferrante/.cargo/registry/src/github.com-1ecc6299db9ec823/anchor-spl-0.7.0/src/token.rs:256:37
    Program 22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD consumed 200000 of 200000 compute units
    Program failed to complete: BPF program panicked
    Program 22Y43yTVxuUkoRKdm9thyRhQ3SdgQS7c7kB6UNCiaczD failed: Program failed to complete

Instead, the program should provide an instructive error code.