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.

did:key:z6MkoohH...AjJf opened with revision d032d53a on base 9ff67562 +46 -4 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.

fintohaps commented on revision 1 1 month ago

This is nice, I like the idea.

To push it forward, I’d like to better encapsulate it, and it make it more resuable for other editing components, e.g. patch editing, rad config editing, rad id editing, etc.

I think if I was doing it, I’d create a new module hierarchy under radicle-cli/src: edit::recover.

In recover, I would have something along the lines of Recover, e.g.

pub struct Recover<Data, W> {
  /// The data that should be recovered into a file or `out`.
  to_recover: Data,
  /// The temporary file that data is recovered in.
  file: NamedTempFile,
  /// If the temporary file fails, then record the data here.
  ///
  /// This will generally be stdout.
  out: W,
}

impl<Data, W> Recover<Data, W> {
  pub fn new(to_recover: Data, out: W) -> Self {
      let file = todo!("Create NamedTempFile");
      Self { to_recover, file, out }
  }

  pub fn stdout(to_recover: Data) -> Self {
      let file = todo!("Create NamedTempFile");
      let stdout = todo!("Construct stdout");
      Self { to_recover, file, out }
  }

  pub fn with_recovery<T, E, F>(self, f: F)
    where
	F: FnOnce() -> Result<T, E>
  {
	todo!("Attempt operation, and if it fails print `self.to_recover`")
  }
}

I’m suggesting generics to make it usable and unit testable.

Let me know what you think!