vfs/
pseudo_directory.rs

1// Copyright 2019 The Fuchsia Authors. All rights reserved.
2// Use of this source code is governed by a BSD-style license that can be
3// found in the LICENSE file.
4
5//! A macro to generate pseudo directory trees using a small DSL.
6
7use zx_status::Status;
8
9/// A helper function used by the `pseudo_directory!` macro, to report nice errors in case
10/// add_entry() fails.
11#[doc(hidden)]
12pub fn unwrap_add_entry_span(entry: &str, location: &str, res: Result<(), Status>) {
13    if res.is_ok() {
14        return;
15    }
16
17    let status = res.unwrap_err();
18    let text;
19    let error_text = match status {
20        Status::ALREADY_EXISTS => "Duplicate entry name.",
21        _ => {
22            text = format!("`add_entry` failed with an unexpected status: {}", status);
23            &text
24        }
25    };
26
27    panic!(
28        "Pseudo directory tree generated via pseudo_directory! macro\n\
29         {}\n\
30         {}\n\
31         Entry: '{}'",
32        location, error_text, entry
33    );
34}