Troubleshooting
This guide covers common issues you may encounter when developing with mik-sdk and their solutions.
Build Issues
Section titled “Build Issues”Missing wasm32-wasip2 Target
Section titled “Missing wasm32-wasip2 Target”Error:
error[E0463]: can't find crate for `core`Solution:
rustup target add wasm32-wasip2cargo-component Not Found
Section titled “cargo-component Not Found”Error:
error: no such command: `component`Solution:
cargo install cargo-componentWIT Dependency Issues
Section titled “WIT Dependency Issues”Error:
error: failed to resolve package `mik:core`Solution: Ensure your wit/ directory structure is correct:
my-handler/└── wit/ ├── world.wit └── deps/ └── core/ └── core.witYour wit/world.wit should include:
package my:handler;
world handler { include mik:core/handler-world;}Bindings Module Missing
Section titled “Bindings Module Missing”Error:
error[E0433]: failed to resolve: could not find `bindings` in the crate rootSolution: The bindings module is generated during build. Ensure you have:
- Correct
Cargo.tomlmetadata:
[package.metadata.component]package = "my:handler"
[package.metadata.component.target.dependencies]"mik:core" = { path = "wit/deps/core" }- Build with cargo-component:
cargo component buildRuntime Issues
Section titled “Runtime Issues”wasmtime Errors
Section titled “wasmtime Errors”Error:
Error: failed to run main moduleSolution: Use the -S cli=y flag for proper stdio support:
wasmtime serve -S cli=y service.wasmComponent Composition Fails
Section titled “Component Composition Fails”Error:
error: failed to plug componentSolution: Ensure both components are built with the same WIT interfaces:
- Use matching mik-bridge version
- Verify WIT versions match:
wasm-tools component wit target/wasm32-wasip2/release/handler.wasmwasm-tools component wit mik-bridge.wasm404 for All Routes
Section titled “404 for All Routes”Symptom: All requests return 404.
Possible causes:
- Routes not defined - Ensure
routes!macro is present:
routes! { GET "/" => home,}- Wrong path format - Paths must start with
/:
// WrongGET "users" => list_users,
// CorrectGET "/users" => list_users,- Component not composed - Ensure you’re running the composed component, not the raw handler.
JSON Issues
Section titled “JSON Issues”JSON Parse Fails
Section titled “JSON Parse Fails”Symptom: req.json() or resp.json() returns None.
Possible causes:
- Invalid JSON - Validate your JSON:
if let Some(parsed) = req.json() { // Valid JSON} else { log::warn!("Invalid JSON received");}- Exceeds size limit - Default max is 1MB:
// Check size before parsingif body.len() > 1_000_000 { return bad_request!("Request body too large");}- Exceeds depth limit - Default max depth is 20:
// Deeply nested JSON may be rejectedpath_str Returns None
Section titled “path_str Returns None”Symptom: parsed.path_str(&["key"]) returns None unexpectedly.
Possible causes:
- Wrong path - Check the actual JSON structure:
// For {"user": {"name": "Alice"}}parsed.path_str(&["user", "name"]) // Correctparsed.path_str(&["name"]) // Wrong - returns None- Wrong type - Use the correct accessor:
// For {"count": 42}parsed.path_str(&["count"]) // None - it's a numberparsed.path_int(&["count"]) // Some(42)Input Validation Issues
Section titled “Input Validation Issues”Required Field Not Detected
Section titled “Required Field Not Detected”Symptom: Handler receives request with missing required field.
Solution: Ensure the field is not Option:
#[derive(Type)]pub struct CreateInput { pub name: String, // Required pub email: Option<String>, // Optional}Default Value Not Applied
Section titled “Default Value Not Applied”Symptom: Query parameter doesn’t have expected default.
Solution: Use #[field(default = value)] on Query types:
#[derive(Query)] // Must be Query, not Typepub struct ListQuery { #[field(default = 1)] pub page: u32,}HTTP Client Issues
Section titled “HTTP Client Issues”Feature Not Enabled
Section titled “Feature Not Enabled”Error:
error: cannot find macro `fetch` in this scopeSolution: The http-client feature is enabled by default. If you disabled default features, re-enable it:
[dependencies]mik-sdk = { version = "0.1", default-features = false, features = ["http-client"] }Request Timeout
Section titled “Request Timeout”Symptom: HTTP requests hang or timeout.
Solution: Set explicit timeouts:
let response = fetch!(GET "https://api.example.com", timeout: 5000 // 5 seconds).send()?;SSRF Protection Blocking Requests
Section titled “SSRF Protection Blocking Requests”Symptom: Requests to internal services fail.
Solution: Only use .deny_private_ips() for user-provided URLs:
// For known internal services - no SSRF protectionlet response = fetch!(GET "http://db-proxy:8080/query").send()?;
// For user-provided URLs - enable SSRF protectionlet response = fetch!(GET &user_url) .deny_private_ips() .send()?;Logging Issues
Section titled “Logging Issues”Logs Not Appearing
Section titled “Logs Not Appearing”Symptom: log::info!() calls don’t produce output.
Solution: Logs go to stderr. When running with wasmtime:
# Logs visible in terminalwasmtime serve -S cli=y service.wasm
# Capture to filewasmtime serve -S cli=y service.wasm 2>logs.txtDebug Logs Missing in Release
Section titled “Debug Logs Missing in Release”Symptom: log::debug!() doesn’t output anything.
This is expected. log::debug!() is compiled out in release builds. Use log::info!() for logs that should always appear, or build in debug mode:
cargo component build # Debug mode - debug! logs appearcargo component build --release # Release mode - debug! compiled outPerformance Issues
Section titled “Performance Issues”Slow JSON Parsing
Section titled “Slow JSON Parsing”Symptom: Handler is slow when parsing large JSON.
Solution: Use lazy path accessors instead of tree traversal:
// Fast - lazy scanning (~100ns per field)let name = parsed.path_str(&["user", "name"]);let age = parsed.path_int(&["user", "age"]);
// Slow - full tree parse (~3000ns+)let name = parsed.get("user").get("name").str();Large Component Size
Section titled “Large Component Size”Symptom: Composed component is larger than expected.
Solutions:
- Build in release mode:
cargo component build --release- Disable unused features:
[dependencies]mik-sdk = { version = "0.1", default-features = false }- Enable LTO:
[profile.release]lto = trueGetting Help
Section titled “Getting Help”If you encounter an issue not covered here:
- Check the examples in the repository
- Review the API reference documentation
- Open an issue on GitHub
Next Steps
Section titled “Next Steps”- Architecture - Understand how components work
- Testing - Test your handlers