mirror of
https://seed.radicle.dev/rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5.git
synced 2026-11-21 14:20:42 +08:00
Handle json! panick trying to serialize non utf8 lines
Instead of panicking when trying to handle non utf8 lines we should return `null` as line output. This way we can on the frontend detect if a file has any lines the api wasn't able to parse and fallback to show a file as a `Binary File`
This commit is contained in:
@@ -1,4 +1,4 @@
|
||||
use radicle_surf as surf;
|
||||
use radicle_surf::{self as surf};
|
||||
use serde_json::{json, Value};
|
||||
|
||||
use radicle::cob;
|
||||
@@ -194,14 +194,14 @@ impl<'a> Modification<'a> {
|
||||
surf::diff::Modification::Addition(addition) => {
|
||||
json!({
|
||||
"type": "addition",
|
||||
"line": addition.line,
|
||||
"line": addition.line.clone().from_utf8().ok(),
|
||||
"lineNo": addition.line_no
|
||||
})
|
||||
}
|
||||
surf::diff::Modification::Deletion(deletion) => {
|
||||
json!({
|
||||
"type": "deletion",
|
||||
"line": deletion.line,
|
||||
"line": deletion.line.clone().from_utf8().ok(),
|
||||
"lineNo": deletion.line_no
|
||||
})
|
||||
}
|
||||
@@ -212,7 +212,7 @@ impl<'a> Modification<'a> {
|
||||
} => {
|
||||
json!({
|
||||
"type": "context",
|
||||
"line": line,
|
||||
"line": line.clone().from_utf8().ok(),
|
||||
"lineNoOld": line_no_old,
|
||||
"lineNoNew": line_no_new
|
||||
})
|
||||
|
||||
@@ -12,7 +12,7 @@ pub(crate) enum Comment<'a> {
|
||||
Issue(&'a cob::thread::Comment),
|
||||
}
|
||||
|
||||
impl<'a> Comment<'a> {
|
||||
impl Comment<'_> {
|
||||
pub fn as_json(&self, id: &Oid, aliases: &impl AliasStore) -> Value {
|
||||
match self {
|
||||
Comment::Issue(c) => json!({
|
||||
|
||||
Reference in New Issue
Block a user