plotly / plotly/plotly.rs

`Plot::show()` panics when no opener binary exists, and silently no-ops when it fails

オープン
#435 コメント 0 件 リアクション 0 件 担当者 0 名 GitHub で見る

まだ誰も着手していません。

主要言語
Rust
スター
1.5k
フォーク
128
PR マージ指標
30日以内にマージされた PR はありません

説明

Plot::show() offers no way for a caller to handle a failed browser handoff.
Running it on a headless server causes a panic, but the panic message is misleading.

How to reproduce

use plotly::{Plot, Scatter};

fn main() {
    let mut plot = Plot::new();
    plot.add_trace(Scatter::new(vec![0, 1, 2], vec![0.0, 1.5, 3.0]));
    plot.show();
}

Run on a headless Linux host with no xdg-open on PATH 👍

thread 'main' panicked at .../plotly-0.14.1/src/plot.rs:789:14:
Could not find default application for HTML files.
[...]
: Os { code: 2, kind: NotFound, message: "No such file or directory" }

Environment

  • plotly 0.14.1
  • rustc 1.98.0
  • AlmaLinux 9.8

Expected

A library call should not abort the process over a missing external binary. The caller should have
some way to detect this and potentially fall back to write_html() or write_image() on its own or
show a clear error message.

Cause

https://github.com/plotly/plotly.rs/blob/00fe0512e9f924bd0fc2edfc6cc617a1604f4e0d/plotly/src/plot.rs#L793-L800

There are two problems with it:

  1. Missing binary panics: .output() returns Err only when the process cannot be
    spawned, i.e. xdg-open is not on PATH. .expect() turns that into a panic, and
    show() returns (), so a caller has nothing to match on.
    The resulting error message is very misleading here: https://github.com/plotly/plotly.rs/blob/00fe0512e9f924bd0fc2edfc6cc617a1604f4e0d/plotly/src/plot.rs#L57-L65

  2. Return code of the xdg-open is ignored: If xdg-open is installed but exits non-zero
    (e.g. when no application is registered for HTML) it still returns Ok, carrying
    the failure inside Output::status, but status is never read.

The macOS and Windows variants have a similar shape.

コントリビューションガイド

コントリビューションガイドを開く

はじめの一歩

  1. issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
  2. 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
  3. リポジトリをフォークし、ブランチを切って変更します。
  4. issue 番号を参照したプルリクエストを送ります。

調査の方向性

plotly/src/plot.rs の参照されている Plot::show() 実装から始め、57-65 行付近のエラー定義を含めて、Linux、macOS、Windows の各分岐を調査してください。headless Linux のケースを再現し、その後、opener バイナリが存在しない場合や opener のステータスがゼロ以外の場合に、panic を発生させたり暗黙に無視したりせず、呼び出し元に報告されることを確認してください。

索引モデルが issue の本文から書いたものです。

評価

技術スタック
rust
領域
data-visualization
issue の種類
バグ
難易度
4/5
見積もり時間
3〜5日
活発さ
活発
明瞭さ
おおむね明確
初心者へのやさしさ
62/100

新しい issue をメールで受け取る

初心者向けの GitHub issue を短くまとめたダイジェスト。