modelscope / modelscope/FunASR

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

Open
#3,523 8 comments 0 reactions 0 assignees View on GitHub

Nobody has claimed this yet.

bug needs feedback
Dominant language
Python
Stars
20.4k
Forks
2k
Avg merge
4h 55m
Merged PRs (30d)
169

Description

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.

Contributor guide

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. Open a pull request that references the issue number.

Research direction

Start with runtime/python/onnxruntime/funasr_onnx/sensevoice_bin.py at the reported lines, then inspect paraformer_online_bin.py and the other *_bin.py files for the same error handling. Check each path that uses a bare except or raises a string, and verify that the original import failure remains visible while unrelated failures are not mislabeled as missing funasr.

Written by the indexing model from the issue text.

Assessment

Tech stack
python
Domain
tooling
Issue type
Bug
Difficulty
3/5
Estimated time
1-2 days
Activity status
Active
Clarity
Mostly clear
Newbie friendliness
70/100

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.