Skip to content

Uses of "do catch" suggest non-working "try" instead #53672

Closed
@RalfJung

Description

@RalfJung

I have code like this

    let action : Result<Action, Error> = do catch {
        let signed_action = base64::decode(form.signed_action.as_str())?;
        let signed_action: SignedAction = deserialize_from_slice(signed_action.as_slice())?;
        signed_action.verify(&config.secrets.action_signing_key)?
    };

after updating nightly, this does not compile any more. It says

error: found removed `do catch` syntax
   --> src/routes.rs:164:42
    |
164 |     let action : Result<Action, Error> = do catch {
    |                                          ^^
    |
    = help: Following RFC #2388, the new non-placeholder syntax is `try`

So I tried

    let action : Result<Action, Error> = try {
        let signed_action = base64::decode(form.signed_action.as_str())?;
        let signed_action: SignedAction = deserialize_from_slice(signed_action.as_slice())?;
        signed_action.verify(&config.secrets.action_signing_key)?
    };

but that does not compile either

error: expected identifier, found keyword `let`
   --> src/routes.rs:164:9
    |
163 |     let action : Result<Action, Error> = try {
    |                                          --- while parsing this struct
164 |         let signed_action = base64::decode(form.signed_action.as_str())?;
    |         ^^^ expected identifier, found keyword

I have also tried try catch, to no avail.

At the very least, the error message about "do catch" needs to be improved, as its advise is clearly incorrect. But also, I wonder what I should do now :D I guess I'll use an immediately-applied closure again...

Metadata

Metadata

Assignees

Labels

C-bugCategory: This is a bug.

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions