dtolnay/cxx

Preserve cause-chain of errors propagated from rust -> c++ -> rust

Aberta

#290 aberto em 9 de set. de 2020

 (1 comentário) (0 reação) (0 responsável)Rust (253 forks)batch import
help wantedneeds design

Métricas do repositório

Stars
 (4.472 estrelas)
Métricas de merge de PR
 (Métricas PR pendentes)

Description

use anyhow::{anyhow, Result};

#[cxx::bridge]
mod ffi {
    extern "C" {
        include!("repro.h");
        fn cthing() -> Result<()>;
    }

    extern "Rust" {
        fn rustthing() -> Result<()>;
    }
}

fn rustthing() -> Result<()> {
    Err(anyhow!("no such file or directory").context("failed to open: /nonexist"))
}

fn main() -> Result<()> {
    ffi::cthing()?;
    Ok(())
}
// repro.cc

void cthing() {
  rustthing();
}

This currently loses the cause chain and only prints:

Error: failed to open: /nonexist

Guia do colaborador