Radish alpha
r
rad:z4V1sjrXqjvFdnCUbxPFqd5p4DtH5
Radicle web interface
Radicle
Git
Handle `json!` panick trying to serialize non utf8 lines
Merged did:key:z6MkkfM3...sVz5 opened 1 year ago

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

check check-visual check-unit-test check-http-client-unit-test check-radicle-httpd check-e2e check-build check-http

👉 Preview 👉 Workflow runs 👉 Branch on GitHub

6 files changed +17 -21 856caf0e → c132855d
modified http-client/lib/repo/commit.ts
@@ -66,7 +66,7 @@ export type CommitBlob = z.infer<typeof commitBlobSchema>;
type AdditionHunkLine = z.infer<typeof additionHunkLineSchema>;

const additionHunkLineSchema = object({
-
  line: string(),
+
  line: string().nullable(),
  lineNo: number(),
  type: literal("addition"),
});
@@ -74,7 +74,7 @@ const additionHunkLineSchema = object({
type DeletionHunkLine = z.infer<typeof deletionHunkLineSchema>;

const deletionHunkLineSchema = object({
-
  line: string(),
+
  line: string().nullable(),
  lineNo: number(),
  type: literal("deletion"),
});
@@ -95,7 +95,7 @@ const diffFileSchema = object({
type ContextHunkLine = z.infer<typeof contextHunkLineSchema>;

const contextHunkLineSchema = object({
-
  line: string(),
+
  line: string().nullable(),
  lineNoNew: number(),
  lineNoOld: number(),
  type: literal("context"),
modified radicle-httpd/build/Dockerfile
@@ -1,5 +1,5 @@
# Builds release binaries for Radicle.
-
FROM rust:1.77.2-alpine3.19 as builder
+
FROM rust:1.83.0-alpine3.21 as builder
LABEL maintainer="Radicle Team <team@radicle.xyz>"
WORKDIR /src
COPY . .
@@ -13,7 +13,7 @@ ARG GIT_HEAD
# Copy cargo configuration we're going to use to specify compiler options.
RUN mkdir -p .cargo && cp build/config.toml .cargo/config.toml
# Install dependencies.
-
RUN apk update && apk add --no-cache git musl-dev minisign curl xz asciidoctor
+
RUN apk update && apk add --no-cache git musl-dev xz asciidoctor zig
# Build man pages and strip metadata. Removes all comments, since they include
# non-reproducible information, such as version numbers.
RUN asciidoctor --doctype manpage --backend manpage --destination-dir . *.1.adoc && \
@@ -27,15 +27,8 @@ RUN rustup target add \

# Install dependencies for cross-compiling to macOS.
# We use Zig as the linker to perform the compilation from a Linux host.
-
# Zig is not yet available on Debian, so we download the official binary.
# Compilation is done via `cargo-zigbuild` which is a wrapper around `zig`.
-
RUN curl -sSf -o zig.tar.xz         https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz && \
-
    curl -sSf -o zig.tar.xz.minisig https://ziglang.org/download/0.12.0/zig-linux-x86_64-0.12.0.tar.xz.minisig && \
-
    minisign -Vm zig.tar.xz -P RWSGOq2NVecA2UPNdBUZykf1CCb147pkmdtYxgb3Ti+JO/wCYvhbAb/U && \
-
    xz -d -c zig.tar.xz | tar -x && \
-
    mv zig-linux-x86_64-0.12.0/zig /usr/bin/zig && \
-
    mv zig-linux-x86_64-0.12.0/lib /usr/lib/zig && \
-
    cargo install cargo-zigbuild@0.18.3 --locked
+
RUN cargo install cargo-zigbuild@0.19.3 --locked


# Parts of the macOS SDK are required to build Radicle, we make these available
@@ -54,7 +47,7 @@ RUN cargo zigbuild --locked --release \

# Now copy the files to a new image without all the intermediary artifacts to
# save some space.
-
FROM alpine:3.19 as packager
+
FROM alpine:3.21 as packager

ARG RADICLE_VERSION
ARG SOURCE_DATE_EPOCH
modified radicle-httpd/rust-toolchain
@@ -1 +1 @@
-
1.77

\ No newline at end of file
+
1.83

\ No newline at end of file
modified radicle-httpd/src/api/json/diff.rs
@@ -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
                })
modified radicle-httpd/src/api/json/thread.rs
@@ -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!({
modified src/views/repos/Changeset/FileDiff.svelte
@@ -39,6 +39,9 @@
  let highlighting: { new?: string[]; old?: string[] } | undefined = undefined;
  let syntaxHighlightingLoading: boolean = false;
  let preview = false;
+
  const binaryLines =
+
    fileDiff.type === "plain" &&
+
    fileDiff.hunks.some(h => h.lines.some(l => !l.line));
  $: extension = filePath.split(".").pop();

  onMount(() => {
@@ -449,7 +452,7 @@
  </svelte:fragment>

  <div class="container">
-
    {#if fileDiff.type === "plain"}
+
    {#if fileDiff.type === "plain" && !binaryLines}
      {#if fileDiff.hunks.length > 0 && !preview}
        <table class="diff" data-file-diff-select>
          <tbody>