fermyon / spin-deps-plugin

Apache License 2.0
0 stars 5 forks source link

Errors adding a dependency to a new project #9

Open itowlson opened 17 hours ago

itowlson commented 17 hours ago

~Unexpected character '/' after patch version number~ (fixed)

Created a new Spin project using the http-rust template then tried to add a dependency to it, but I got a cryptic error:

$ spin deps add ~/github/wasi-key-value-sample/qr-generator-cached/target/wasm32-unknown-unknown/release/qr_generator_cached.wasm
Select packages to import (use space to select, enter to confirm): example:qr@1.0.0
Select one or all interfaces to import from package 'example:qr@1.0.0': qr
Select a component to add the dependency to: deps-plugin-test
Error: unexpected character '/' after patch version number

A .wit directory was created with the right tree underneath it, and deps.wit looks reasonable, but nothing was added to spin.toml.

World contains different number of imports than expected

I am not sure if this is related or a different error or related, but when I then tried to add a second component, I got a different error:

$ spin deps add ~/testing/vscode-wasm-component-model-sample/calculator-impl/target/wasm32-unknown-unknown/release/calculator_impl.wasm 
Select packages to import (use space to select, enter to confirm): vscode:example
Select one or all interfaces to import from package 'vscode:example': types
Select a component to add the dependency to: deps-plugin-test
Error: failed to merge package `root:component` into existing copy

Caused by:
    0: failed to merge world `dependency-world`
    1: world contains different number of imports than expected

This second component was not added to deps.wit (or to spin.toml).

itowlson commented 16 hours ago

If I do the same two dependencies the other way round, the first (calculator) succeeds, but the second (QR) fails. The failure on the second has the "different number of imports" message (not the "patch version number" it had when it was going first).

My guess is that there is some issue with merging WITs. So a second dep always fails at the first hurdle. But that the "patch version" error happens only in the spin.toml phase, by which time the WIT has already been written.

(As Karthik has noted, this was written as an experiment. So it totally makes sense that managing these kinds of errors and partial failures wasn't a priority. But even in experimental stage, it's so good that we are recommending it in blogs (and I've had people asking me why it's not in the docs). So we maybe need to plan on investing in it, and specifically in its failure modes...!)

itowlson commented 16 hours ago

~I think the error with the qr dep may be that it imports the wasi:keyvalue interface and we don't know what to do with that?~ I was wrong.

itowlson commented 13 hours ago

Okay the issue with the qr dep is that the interface is versioned. The plugin currently tries to form a DependencyName from <full-package-name>/<interface-name> which in the versioned case gives us e.g. example:qr@1.0.0/qr. This is malformed: it needs to be example:qr/qr@1.0.0. Fix in progress.