プロジェクト

全般

プロフィール

バグ #1227

完了

本文に実体参照を含むツイートにEntityも含まれていた場合、インデックスがずれる

toshi_a 初音 さんがほぼ6年前に追加. ほぼ6年前に更新.

ステータス:
終了
優先度:
通常
担当者:
-
対象バージョン:
プラグイン名:
ブランチ:
クラッシュする:
はい

説明

再現手順を実行すると、以下のようなバックトレースを出力してmikutterがクラッシュすることがあった。
もう一度起動すると正常に起動するが、REST APIリクエストが完了してTLにツイートが反映された後にクラッシュする。そのさいのバックトレースも以下の内容と同じ。

/home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:472:in `score_by_regexp': undefined method `partition' for nil:NilClass (NoMethodError)
    from /home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:458:in `score_by_screen_name_regexp'
    from /home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:308:in `block (2 levels) in <top (required)>'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/filter.rb:28:in `filtering'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:59:in `block (2 levels) in filtering'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:58:in `each'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:58:in `reduce'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:58:in `block in filtering'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:57:in `catch'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/event.rb:57:in `filtering'
    from /home/toshi/.gem/ruby/2.5.0/gems/pluggaloid-1.1.1/lib/pluggaloid/plugin.rb:63:in `filtering'
    from /home/toshi/Projects/mikutter/core/plugin/score/select.rb:7:in `score_by_score'
    from /home/toshi/Projects/mikutter/core/plugin/score/select.rb:41:in `block (2 levels) in score_expand'
    from /home/toshi/Projects/mikutter/core/plugin/score/select.rb:39:in `each'
    from /home/toshi/Projects/mikutter/core/plugin/score/select.rb:39:in `block in score_expand'
    from /home/toshi/Projects/mikutter/core/mui/cairo_markup_generator.rb:34:in `each'
    from /home/toshi/Projects/mikutter/core/mui/cairo_markup_generator.rb:34:in `each'
    from /home/toshi/Projects/mikutter/core/mui/cairo_markup_generator.rb:34:in `inject'
    from /home/toshi/Projects/mikutter/core/mui/cairo_markup_generator.rb:34:in `description_attr_list'
    from /home/toshi/Projects/mikutter/core/lib/uithreadonly.rb:22:in `block (2 levels) in singleton class'
    from /home/toshi/Projects/mikutter/core/mui/cairo_miracle_painter.rb:350:in `main_message'
    from /home/toshi/Projects/mikutter/core/lib/uithreadonly.rb:22:in `block (2 levels) in singleton class'
    from /home/toshi/Projects/mikutter/core/mui/cairo_coordinate_module.rb:48:in `height'
    from /home/toshi/Projects/mikutter/core/lib/uithreadonly.rb:22:in `block (2 levels) in singleton class'
    from /home/toshi/Projects/mikutter/core/mui/cairo_cell_renderer_message.rb:145:in `render_message'
    from /home/toshi/Projects/mikutter/core/mui/cairo_cell_renderer_message.rb:128:in `uri='
    from /home/toshi/Projects/mikutter/core/plugin/gtk/mainloop.rb:10:in `main'
    from /home/toshi/Projects/mikutter/core/plugin/gtk/mainloop.rb:10:in `mainloop'
    from /home/toshi/Projects/mikutter/mikutter.rb:68:in `boot!'
    from /home/toshi/Projects/mikutter/mikutter.rb:104:in `<main>'

再現手順

  1. 凍結されたmikutterのCKを使ったアカウントの認証を解除する
  2. mikutterを終了し、CK/CSを有効なものに書き換える
  3. mikutterを起動する
  4. 適当なTwitterアカウントでWorldを作成する

toshi_a 初音 さんがほぼ6年前に更新

雑なprintデバッグで、text noteのdescriptionがセットされずに作られてることが確認できた。nilガードで場当たり的に対応できなくもないが、根本的に直すべきですね

      if !note.description.is_a?(String)
        error "model: #{message.inspect}, note: #{note.inspect}" 
      end

toshi_a 初音 さんがほぼ6年前に更新

  • ステータス新規 から 実装待ち に変更

Akira Ouchi さんがほぼ6年前に更新

git rebaseで適当に遡って確かめた感じ、以下のコミットからクラッシュするようになったようです。
https://dev.mikutter.hachune.net/projects/mikutter/repository/revisions/0be9a6fc56c75bb5a92c3e6eec5fb596b06d9b3c

toshi_a 初音 さんがほぼ6年前に更新

そこでクラッシュするようになったということは、もともとあった不具合がその変更によって顕在化したようですね

toshi_a 初音 さんがほぼ6年前に更新

/home/toshi/Projects/mikutter/core/plugin/score/model/text_note.rb:11:in `initialize': Invalid description value `nil'. (RuntimeError)
    from /home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:357:in `new'
    from /home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:357:in `score_by_entity'
...

Divaにnullability実装してなかったっけ(痴呆)などと言いながら問題箇所を確認したところ(twitter.rb:357)

    if cur != text.size
      score << Diva::Model(:score_text).new(
        description: text[cur...text.size])
    end

String#[]にRangeを渡した場合、一部の状況においてnilを返すので 、このあたりの処理がおかしいようですね。

toshi_a 初音 さんがほぼ6年前に更新

/home/toshi/Projects/mikutter/core/plugin/twitter/twitter.rb:361:in `score_by_entity': base string: "> mikutterのtterは、過去のTwitterからとったもので、現在のTwitterのそれではありません。 (RuntimeError)

// mikutterのTwitterコンシューマキーが凍結されました - mikutter blog https://t.co/glpccypbrp", range: 137...134

Range#firstがlastより大きな値になってますが、この時のlastはdescription#size、firstは寸前のTwitter Entityのlastの値なので、Twitter Entityのインデックスとしてそもそも間違った値が送られてきているか、例外の考慮漏れである可能性が出てきました。

toshi_a 初音 さんがほぼ6年前に更新

descriptionが返す文字列の、>などを>などに置き換えていますが、この置き換えによってEntityのインデックスがずれてしまうことが原因だということがわかりました。
descriptionの返す文字列ではこのような置き換えを行わず、TwitterプラグインがTextNoteを作るタイミングで置き換えるべきでしょう。

toshi_a 初音 さんがほぼ6年前に更新

  • 題名CK/CSを書き換えてから認証するとクラッシュする から 本文に実体参照を含むツイートにEntityも含まれていた場合、インデックスがずれる に変更

toshi_a 初音 さんがほぼ6年前に更新

  • ステータス実装待ち から 終了 に変更

実装してmergeした

他の形式にエクスポート: Atom PDF