#Hi All, I want to simply write a function to get a String as a input and return its Base64 Decode.

1 messages · Page 1 of 1 (latest)

vapid lichen
#

I tried the below sample code.


    string decodedString = check mime:base64Decode(estr).ensureType();
    return decodedString;
}```

This returns the error 

ERROR [main.bal:(28:17,28:56)] invalid usage of the 'check' expression operator: no matching error return type(s) in the enclosing invokable
ERROR [main.bal:(47:27,47:72)] invalid usage of the 'check' expression operator: no matching error return type(s) in the enclosing invokable

Can Someone help me ??
#

Without ensureType I am getting a different error.

ERROR [main.bal:(75:34,75:57)] incompatible types: expected '(string|error)', found '(string|byte[]|ballerina/io:1.5.0:ReadableByteChannel|ballerina/mime:2.8.0:DecodeError)'

hoary skiff
#

"invalid usage of the 'check' expression operator: no matching error return type(s) in the enclosing invokable" this error is logged when with check you do not have corresponding error types in the return type of the function (or the checked error isn't handled in some other way).

But in the snippet you shared, since you have error in the return type, it should work. It does work for me. Is the exact code snippet you're getting the error for?

vapid lichen
#

yes

#

❯ bal version
Ballerina 2201.7.2 (Swan Lake Update 7)
Language specification 2023R1
Update Tool 1.3.15

#

This is my ballerina version

hoary skiff
#

Based on the errors, there seem to be at least two check expressions. Is the second one from a different function? Is the line number change expected between with and without ensureType?

vapid lichen
#

I posted a simplified version of the original. Let me check if there is anything