Skip to content

Troubleshooting

This guide covers common issues you may encounter when developing with mik-sdk and their solutions.

Error:

error[E0463]: can't find crate for `core`

Solution:

Terminal window
rustup target add wasm32-wasip2

Error:

error: no such command: `component`

Solution:

Terminal window
cargo install cargo-component

Error:

error: failed to resolve package `mik:core`

Solution: Ensure your wit/ directory structure is correct:

my-handler/
└── wit/
├── world.wit
└── deps/
└── core/
└── core.wit

Your wit/world.wit should include:

package my:handler;
world handler {
include mik:core/handler-world;
}

Error:

error[E0433]: failed to resolve: could not find `bindings` in the crate root

Solution: The bindings module is generated during build. Ensure you have:

  1. Correct Cargo.toml metadata:
[package.metadata.component]
package = "my:handler"
[package.metadata.component.target.dependencies]
"mik:core" = { path = "wit/deps/core" }
  1. Build with cargo-component:
Terminal window
cargo component build

Error:

Error: failed to run main module

Solution: Use the -S cli=y flag for proper stdio support:

Terminal window
wasmtime serve -S cli=y service.wasm

Error:

error: failed to plug component

Solution: Ensure both components are built with the same WIT interfaces:

  1. Use matching mik-bridge version
  2. Verify WIT versions match:
Terminal window
wasm-tools component wit target/wasm32-wasip2/release/handler.wasm
wasm-tools component wit mik-bridge.wasm

Symptom: All requests return 404.

Possible causes:

  1. Routes not defined - Ensure routes! macro is present:
routes! {
GET "/" => home,
}
  1. Wrong path format - Paths must start with /:
// Wrong
GET "users" => list_users,
// Correct
GET "/users" => list_users,
  1. Component not composed - Ensure you’re running the composed component, not the raw handler.

Symptom: req.json() or resp.json() returns None.

Possible causes:

  1. Invalid JSON - Validate your JSON:
if let Some(parsed) = req.json() {
// Valid JSON
} else {
log::warn!("Invalid JSON received");
}
  1. Exceeds size limit - Default max is 1MB:
// Check size before parsing
if body.len() > 1_000_000 {
return bad_request!("Request body too large");
}
  1. Exceeds depth limit - Default max depth is 20:
// Deeply nested JSON may be rejected

Symptom: parsed.path_str(&["key"]) returns None unexpectedly.

Possible causes:

  1. Wrong path - Check the actual JSON structure:
// For {"user": {"name": "Alice"}}
parsed.path_str(&["user", "name"]) // Correct
parsed.path_str(&["name"]) // Wrong - returns None
  1. Wrong type - Use the correct accessor:
// For {"count": 42}
parsed.path_str(&["count"]) // None - it's a number
parsed.path_int(&["count"]) // Some(42)

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
}

Symptom: Query parameter doesn’t have expected default.

Solution: Use #[field(default = value)] on Query types:

#[derive(Query)] // Must be Query, not Type
pub struct ListQuery {
#[field(default = 1)]
pub page: u32,
}

Error:

error: cannot find macro `fetch` in this scope

Solution: 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"] }

Symptom: HTTP requests hang or timeout.

Solution: Set explicit timeouts:

let response = fetch!(GET "https://api.example.com",
timeout: 5000 // 5 seconds
).send()?;

Symptom: Requests to internal services fail.

Solution: Only use .deny_private_ips() for user-provided URLs:

// For known internal services - no SSRF protection
let response = fetch!(GET "http://db-proxy:8080/query").send()?;
// For user-provided URLs - enable SSRF protection
let response = fetch!(GET &user_url)
.deny_private_ips()
.send()?;

Symptom: log::info!() calls don’t produce output.

Solution: Logs go to stderr. When running with wasmtime:

Terminal window
# Logs visible in terminal
wasmtime serve -S cli=y service.wasm
# Capture to file
wasmtime serve -S cli=y service.wasm 2>logs.txt

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:

Terminal window
cargo component build # Debug mode - debug! logs appear
cargo component build --release # Release mode - debug! compiled out

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();

Symptom: Composed component is larger than expected.

Solutions:

  1. Build in release mode:
Terminal window
cargo component build --release
  1. Disable unused features:
[dependencies]
mik-sdk = { version = "0.1", default-features = false }
  1. Enable LTO:
[profile.release]
lto = true

If you encounter an issue not covered here:

  1. Check the examples in the repository
  2. Review the API reference documentation
  3. Open an issue on GitHub