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

Bad type cast on a StorageMap return results in a vague error message #141

Open
roschler opened this issue Jul 6, 2021 · 0 comments
Open

Comments

@roschler
Copy link

roschler commented Jul 6, 2021

In the code below, I used the wrong key field to retrieve a StorageMap value. This result in a bad cast attempt, trying to cast a BigInteger value to a UInt160 value. This produced a strange VM exception that doesn't indicate the actual error.

Here's the code:

        private static UInt160 getOwner()
        {
            var ownerVal =  (UInt160) ContractMetadata.Get(VARNAME_WRONG_KEY_FIELD_NAME);

            // Convert null to UInt160.Zero.
            if (ownerVal == null)
                return UInt160.Zero;
            return ownerVal;
        }

VARNAME_WRONG_KEY_FIELD_NAME belongs to a BigInteger value in the storage map, not a UInt160.

Here's the error message:

Engine State Fault: An unhandled exception was thrown. (���	ZT� ����`��cs�?؏ [VMUnhandledException]
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant