Skip to content

High: 7 sites in Core/Tensor.jl discard Rust error messages #107

@shinaoka

Description

@shinaoka

AGENTS.md で「Never discard the Rust error message returned through last_error_message()」と定められていますが、src/Core/Tensor.jl の 7 箇所で Rust エラーメッセージが破棄されています。

違反箇所

すべて src/Core/Tensor.jl 内。これらの関数は _core_last_backend_error_message() を呼ばずに、ジェネリックな throw(ArgumentError(...)) でステータスコードだけをチェックしています:

# Line Function 現在のメッセージ
1 378 _read_core_csize_vector_from_handle (query) "querying backend tensor $context failed"
2 390 _read_core_csize_vector_from_handle (copy) "copying backend tensor $context failed"
3 411 _tensor_scalar_kind_from_owned_handle "querying backend tensor scalar kind failed"
4 449 _read_dense_f64_from_owned_handle (query) "querying backend dense tensor data failed"
5 461 _read_dense_f64_from_owned_handle (copy) "copying backend dense tensor data failed"
6 565 _read_dense_c64_from_owned_handle (query) "querying backend dense tensor data failed"
7 577 _read_dense_c64_from_owned_handle (copy) "copying backend dense tensor data failed"

修正方針

同じファイル内の _core_check_backend_status (line 80-88) が正しいパターンを定義しています:

function _core_check_backend_status(status, context)
    status == _CORE_T4A_SUCCESS && return
    msg = _core_last_backend_error_message()
    msg === nothing && throw(ArgumentError("$context failed"))
    throw(ArgumentError("$context: $msg"))
end

上記 7 箇所を _core_check_backend_status(status, "...") を使うように置き換える。

発見経緯

AGENTS.md 監査。同ファイル内の他の関数(_read_core_cptrdiff_vector_from_handle 等)は正しく _core_check_backend_status を使用しており、不整合が生じています。

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions