wit-bindgen icon indicating copy to clipboard operation
wit-bindgen copied to clipboard

cli: better error messaging around "interface/package" not found

Open chrisdickinson opened this issue 1 year ago • 4 comments
trafficstars

Hi! I was following along with the wasi-logging proposal, but couldn't get wit-bindgen to generate markdown:

$ wit-bindgen rust wit/world.wit
Error: interface or world `logging` does not exist
     --> wit/world.wit:4:12
      |
    4 |     import logging;
      |

After a little while I realized that somewhere along the line, I had started passing a full file path to wit-bindgen instead of a directory – wit-bindgen markdown wit/world.wit instead of wit-bindgen markdown wit.

Would you be amenable to adding a hint to the error output in the case where a package couldn't be found, but the input was a single file? (I'd be happy to make a PR!)

chrisdickinson avatar Dec 14 '23 23:12 chrisdickinson

Thanks for the report! I agree it'd be nice to have a better error message here. Implementing this though won't be easy since the configuration of what's taken as input is pretty far from where this error message is generated. If you're interested though the place to start looking would be the wit-parser crate in the wasm-tools repository

alexcrichton avatar Dec 15 '23 16:12 alexcrichton

One suggestion (that would have saved me hours): Instead of asking for a "WIT document" in the CLI help blob, maybe be explicit about the fact that passing a directory is even an option?

I was scratching my head for a loooong time trying to figure out why wit-bindgen rust didn't even work for the test cases in this repository, until I found this issue and realized that I needed to pass it the directory containing the .wit file, rather than the .wit file itself.

To others finding this: .wit files that depend on their siblings, or on .wit files in a wit/deps/ directory (also a bit under-documented and magic), it seems that you MUST pass a directory, rather than, say, the specific file containing the world (which would be a common mistake when there is one .wit file for your package, but it has dependencies in wit/deps/). Otherwise you get these fairly cryptic "package not found" or "interface not found" errors.

simonask avatar Jun 04 '24 22:06 simonask

Thanks for the suggestion! I've added some updates to https://github.com/bytecodealliance/wit-bindgen/pull/970

alexcrichton avatar Jun 07 '24 15:06 alexcrichton