funasr_onnx: bare `raise "string"` masks the real exception (TypeError: exceptions must derive from BaseException)

Abierto
#3,523 8 comentarios 0 reacciones 0 asignados Ver en GitHub

Nadie ha tomado este issue todavía.

Evaluación

Dificultad
3/5
Tiempo estimado
1-2 días
Aptitud para principiantes
70/100
Tipo de issue
Error
Claridad
Bastante claro
Estado de actividad
Activo
Stack tecnológico
python
Área
tooling

Línea de trabajo

Comienza con runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py en las líneas indicadas y, después, inspecciona paraformer_online_bin.py y los demás archivos *_bin.py en busca del mismo manejo de errores. Comprueba cada ruta que use un bare except o lance un string, y verifica que el error de importación original siga siendo visible, mientras que los errores no relacionados no se etiqueten erróneamente como ausencia de funasr.

Escrito por el modelo de indexación a partir del texto del issue.

Descripción

bug needs feedback

Several error paths in funasr_onnx do raise "some message". That is invalid in Python 3 — a string is not an exception — so the interpreter discards the intended message and raises TypeError: exceptions must derive from BaseException instead.

Combined with the surrounding bare except:, the actual cause is swallowed entirely.

Where

runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py (current main), lines 50, 54, 66:

try:
    from funasr import AutoModel
except:
    raise "You are exporting onnx, please install funasr and try it again. ..."

The same pattern appears in paraformer_online_bin.py and other *_bin.py files.

What the user sees
File ".../funasr_onnx/sensevoice_bin.py", line 66, in __init__
    raise "You are exporting onnx, please install funasr and try it again..."
TypeError: exceptions must derive from BaseException
What was actually wrong

In my case funasr was installed. The import failed on a missing transitive
dependency:

File ".../funasr/utils/load_utils.py", line 9, in <module>
    import torchaudio
ModuleNotFoundError: No module named 'torchaudio'

The message told me to install a package I already had, while hiding the one I was
missing. Diagnosing it required reading the library source and reproducing the import
by hand.

I hit the same thing a second time on onnxscript (required by newer torch.onnx),
and again when loading a model from a local path — line 54 fires whenever the path
check fails for any reason, so a simple wrong-path mistake also surfaces as
TypeError.

Suggested fix
try:
    from funasr import AutoModel
except ImportError as e:
    raise ImportError(
        "Exporting ONNX requires funasr: pip3 install -U funasr"
    ) from e

raise ... from e keeps the original traceback, so a missing torchaudio stays
visible. Narrowing except: to except ImportError: also stops unrelated failures
from being reported as a missing package.

Happy to send a PR if that would help.

Lenguaje dominante
Python
Estrellas
20.4k
Forks
2k
Merge medio
4 h 55 min
PR fusionados (30 d)
169

Guía de contribución

Abrir la guía de contribución

Primeros pasos

  1. Lee el issue completo y luego la guía de contribución del proyecto.
  2. Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
  3. Haz un fork del repositorio y trabaja en una rama.
  4. Abre un pull request que haga referencia al número del issue.

Más de modelscope/FunASR

Todos los issues de modelscope/FunASR

Issues similares

Más issues de Python

Recibe los nuevos issues en tu correo

Un resumen breve de issues de GitHub para principiantes.