Skip to content

fix: raise a clear error when the wasmtime native lib is missing libgcc - #160

Open
qw-in wants to merge 1 commit into
mainfrom
fix/friendly-libgcc-error
Open

fix: raise a clear error when the wasmtime native lib is missing libgcc#160
qw-in wants to merge 1 commit into
mainfrom
fix/friendly-libgcc-error

Conversation

@qw-in

@qw-in qw-in commented Jun 30, 2026

Copy link
Copy Markdown
Member

Proposed solution for #159 but not sure its a good idea/worth it!

wasmtime-py's bundled native library needs libgcc_s.so.1, which most distros ship by default but Alpine Linux does not. Previously this surfaced as a raw ctypes OSError several frames deep, with no indication of the actual fix.

Now arcjet._local catches that specific OSError signature on import and re-raises a clear ArcjetRuntimeError pointing at apk add libgcc. Any other OSError (a different missing library, permissions, etc.) is left untouched so we don't misdiagnose unrelated failures.

Verified in Docker (astral/uv:python3.10-alpine): fails with the new clear error before apk add libgcc, imports cleanly after.

Fixes #159.

wasmtime-py's bundled native library needs libgcc_s.so.1, which most
distros ship by default but Alpine Linux does not. Previously this
surfaced as a raw ctypes OSError several frames deep, with no
indication of the actual fix.

Now arcjet._local catches that specific OSError signature on import and
re-raises a clear ArcjetRuntimeError pointing at `apk add libgcc`. Any
other OSError (a different missing library, permissions, etc.) is left
untouched so we don't misdiagnose unrelated failures.

Verified in Docker (astral/uv:python3.10-alpine): fails with the new
clear error before `apk add libgcc`, imports cleanly after.

Fixes #159.
@qw-in
qw-in requested a review from arcjet-rei June 30, 2026 22:52
@qw-in qw-in self-assigned this Jun 30, 2026
Copilot AI review requested due to automatic review settings June 30, 2026 22:52

@arcjet-review arcjet-review Bot left a comment

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Arcjet Review — 🟢 Low Risk

Decision: Approved

Rationale: Small, well-scoped change that adds a new ArcjetRuntimeError exception and wraps the wasmtime-dependent imports in try/except to translate a specific known OSError (missing libgcc) into a clearer, actionable error message. Unrelated OSErrors are passed through unchanged, avoiding misdiagnosis. The change is covered by three new unit tests verifying both translation and pass-through behavior. No security-sensitive surface area is touched; the error message contains no secrets or user-controlled data, and the substring match is on the exception text only.

Summary of Changes

Adds an ArcjetRuntimeError exception and wraps arcjet._analyze imports so that a wasmtime native-library load failure caused by a missing libgcc (common on Alpine) is re-raised with an actionable message pointing at apk add libgcc. Other OSErrors are passed through unchanged. Includes unit tests for the translation helper.

Notes

Diff is well under the 1000-line size threshold. No escalation triggers fired. Security review checklist applied: no auth, injection, secrets, crypto, or data-protection concerns; error message is static text plus the original exception string (no user input).

Review: 03488761 | Model: anthropic/claude-opus-4-7 | Powered by Arcjet Review

Comment thread src/arcjet/_local.py
)
except OSError as exc:
raise _translate_wasmtime_import_error(exc) from exc

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Consider whether OSError is narrow enough here. The wrapped import block pulls in arcjet._analyze, which may itself raise other OSErrors (e.g. a file-not-found while loading a WASM blob, or unrelated I/O during module init) that aren't actually about wasmtime's native lib. The _translate_wasmtime_import_error helper already passes those through unchanged, so behavior is safe — but the surrounding comment/intent suggests this except is specifically for wasmtime. Worth a brief comment clarifying that the narrowing happens inside the helper, or alternatively catching at a tighter scope around just the wasmtime-triggering import.

Comment thread src/arcjet/_local.py
if _MISSING_LIBGCC_SIGNATURE in str(exc):
return ArcjetRuntimeError(
"Arcjet's local WebAssembly runtime (wasmtime) could not load "
"because `libgcc` is missing. Most Linux distributions include "

Copy link
Copy Markdown

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Nit: the signature match is case-sensitive substring against str(exc). If a future wasmtime/loader version formats the message differently (e.g. uppercase, or routes through repr), this will silently stop translating. Consider matching case-insensitively, or matching on just libgcc plus an indicator like wasmtime to be a bit more robust — at the cost of a slightly broader match. Current behavior is defensible; flagging only as a future-proofing consideration.

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Pull request overview

This PR improves the developer experience when Arcjet’s local WASM runtime (wasmtime) fails to import on Alpine Linux due to a missing libgcc_s.so.1, by translating that specific OSError into a clearer Arcjet-specific runtime error and adding focused tests for the translation behavior.

Changes:

  • Add _translate_wasmtime_import_error() in arcjet._local to map the known missing-libgcc import failure to an ArcjetRuntimeError with actionable guidance.
  • Introduce ArcjetRuntimeError as a new SDK error type for native runtime dependency load failures.
  • Add unit tests validating that only the known libgcc signature is translated and other OSErrors pass through unchanged.

Reviewed changes

Copilot reviewed 3 out of 3 changed files in this pull request and generated 1 comment.

File Description
src/arcjet/_local.py Adds import-time translation of the specific wasmtime missing-libgcc OSError into a clearer ArcjetRuntimeError.
src/arcjet/_errors.py Introduces ArcjetRuntimeError for runtime/native dependency failures.
tests/test_local.py Adds test coverage for the new wasmtime-import error translation helper.

💡 Add Copilot custom instructions for smarter, more guided reviews. Learn how to get started.

Comment thread src/arcjet/_local.py
Comment on lines +76 to +77
except OSError as exc:
raise _translate_wasmtime_import_error(exc) from exc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Not building on python3.10-alpine

2 participants