Radish alpha
h
rad:z3gqcJUoA1n9HaHKufZs5FCSGazv5
Radicle Heartwood Protocol & Stack
Radicle
Git
Try to make sure that issue text is not lost on creation failure
Open did:key:z6MkoohH...AjJf opened 1 month ago

This patch solves

2f43c1e2d1616b07e13e3f8f0b0dcb397aa8fb7c

by trying to rescue the issue title and description. If the issue creation fails, it tries to open a named tempfile and print title and description to that file (plus flushing it). If any of these steps fail, it prints the issue to the terminal. If it succeeds, it prints the path of the tempfile. Then, normal error propagation continues.


This is mostly a proposal. I am sure this code could be made nicer in some way, but I tried to make it as KISS as possible.

1 file changed +46 -4 9ff67562 3a6e5fbe
modified crates/radicle-cli/src/commands/issue.rs
@@ -387,14 +387,24 @@ where
    } else {
        anyhow::bail!("aborting issue creation due to empty title or description");
    };
-
    let issue = cache.create(
-
        title,
-
        description,
+

+
    let creation = cache.create(
+
        title.clone(),
+
        description.clone(),
        labels.as_slice(),
        assignees.as_slice(),
        [],
        signer,
-
    )?;
+
    );
+

+
    let issue = match creation {
+
        Ok(issue) => issue,
+
        Err(error) => {
+
            eprintln!("Issue creation failed, trying to safe issue text to file");
+
            rescue_issue(title, description);
+
            return Err(error.into());
+
        }
+
    };

    if !quiet {
        term::issue::show(&issue, issue.id(), Format::Header, verbose, profile)?;
@@ -402,6 +412,38 @@ where
    Ok(())
}

+
fn rescue_issue(title: Title, description: String) {
+
    use std::io::Write;
+

+
    let mut tempfile = match tempfile::NamedTempFile::new() {
+
        Ok(tempfile) => tempfile,
+
        Err(tempfile_error) => {
+
            eprintln!(
+
                "Tempfile creation failed, falling back to print the issue ({tempfile_error:?})"
+
            );
+
            println!("{title}\n\n{description}");
+
            return;
+
        }
+
    };
+

+
    tempfile.disable_cleanup(true);
+
    let tempfile_path = tempfile.path().to_path_buf();
+

+
    if let Err(write_error) = write!(tempfile, "{}\n\n{}", title, description) {
+
        eprintln!("Writing tempfile failed, falling back to print the issue ({write_error:?})");
+
        println!("{title}\n\n{description}");
+
        return;
+
    }
+

+
    if let Err(flush_error) = tempfile.flush() {
+
        eprintln!("Flushing tempfile failed, just to be sure printing the issue text to terminal ({flush_error:?})");
+
        println!("{title}\n\n{description}");
+
        return;
+
    }
+

+
    println!("Issue was written to: {}", tempfile_path.display());
+
}
+

fn edit<'a, 'g, R, G>(
    issues: &'g mut issue::Cache<issue::Issues<'a, R>, cob::cache::StoreWriter>,
    repo: &storage::git::Repository,