Invalid discriminant for `option`
Hey all, Just tried spin out for the first time and tried to build the hello-rust example and I'm running into the following situation:
Expected Behavior
HTTP/1.1 200 OK
foo: bar
content-length: 15
Hello, Fermyon!
Steps to Reproduce the Problem
- Follow installation guide using cargo
- Build new project using: spin new http-rust spin-hello-world
- Run: spin build --up
- Make a request with: curl -i localhost:3000/hello
Actual Behavior
I get a response of:
HTTP/1.1 500 Internal Server Error
content-length: 0
With a log of:
ERROR spin_http_engine: Error processing request: invalid discriminant for `option`
Specifications
- Version: 0.3.0
- Platform: Intel Mac running MacOS 12.4
As I said this is the first time I've built spin so not sure where to debug this
Hi, @Dueen, thanks for reporting the issue!
Would you mind first exporting the RUST_LOG=spin=trace environment variable, so we get a bit more detailed output?
The error is really confusing. So first things first:
- what happens if you run the
cargo buildmanually? (the one executing when runningspin build) - is there a Wasm binary in
/target/wasm32-wasi/release/? - I assume you are seeing this error when running `spin up?
Thanks!
@radu-matei Yes, running cargo build does give me a /target/wasm32-wasi/release/ directory. And I see the error when making a request to /hello , however testing the /healthz path gives me a success response.
This is what my trace looks like with RUST_LOG=spin=trace:
TRACE spin_cli::commands::up: Running trigger executor: "/Users/usr/.cargo/bin/spin" "trigger" "http"
2022-07-06T08:01:13.014532Z TRACE build: spin_engine: Created module for component spin-hello-world from file "/Users/usr/Repos/spin-hello-world/target/wasm32-wasi/release/spin_hello_world.wasm"
2022-07-06T08:01:13.022350Z TRACE build: spin_engine: Created pre-instance from module for component spin-hello-world.
2022-07-06T08:01:13.022377Z TRACE build: spin_engine: Execution context initialized.
2022-07-06T08:01:13.023528Z TRACE spin_http_engine: Constructed router for application spin-hello-world: {Exact("/hello"): "spin-hello-world"}
Serving http://127.0.0.1:3000
2022-07-06T08:01:13.023881Z INFO spin_http_engine: Serving http://127.0.0.1:3000
Available Routes:
spin-hello-world: http://127.0.0.1:3000/hello
2022-07-06T08:01:28.817761Z INFO spin_http_engine: Processing request for application spin-hello-world on URI http://localhost:3000/hello
2022-07-06T08:01:28.817827Z TRACE spin_http_engine::spin: Executing request using the Spin executor for component spin-hello-world
2022-07-06T08:01:28.819241Z TRACE prepare_component{component="spin-hello-world" env=None args=None}: spin_engine: Preparing component spin-hello-world
2022-07-06T08:01:28.819261Z TRACE prepare_component{component="spin-hello-world" env=None args=None}: spin_engine: Creating store.
2022-07-06T08:01:28.822566Z TRACE spin_engine: Saving logs to "/Users/usr/.spin/spin-hello-world/logs/spin-hello-world_stdout.txt" "/Users/usr/.spin/spin-hello-world/logs/spin-hello-world_stderr.txt"
2022-07-06T08:01:28.823099Z ERROR spin_http_engine: Error processing request: invalid discriminant for `option`
^C
2022-07-06T08:11:48.164559Z INFO spin_trigger::cli: User requested shutdown: exiting
However the stderr log file is empty
Would you mind showing your spin.toml file, please?
Ah, it just occurred to me.
Are you running the templates from the main branch, or from the latest stable release?
Could you run spin templates install --git https://github.com/fermyon/spin --branch v0.3.0 --update, then try running creating a new application again?
My spin.toml file:
spin_version = "1"
authors = ["Author Name <[email protected]>"]
description = "Test Project"
name = "spin-hello-world"
trigger = { type = "http", base = "/" }
version = "0.3.0"
[[component]]
id = "spin-hello-world"
source = "target/wasm32-wasi/release/spin_hello_world.wasm"
[component.trigger]
route = "/hello"
[component.build]
command = "cargo build --target wasm32-wasi --release"
ERROR spin_http_engine: Error processing request: invalid discriminant for
option
This error is usually due to a wit-bindgen mismatch between build and run time, and may be related to https://github.com/fermyon/spin/pull/574, which I merged yesterday.
If you're using spin built from the main branch, you'll want to do the following:
spin templates install --git https://github.com/fermyon/spin --branch main --update
spin new http-rust spin-hello-world
Then edit the generated Cargo.toml file under the spin-hello-world directory, removing the , tag = "v0.3.0" part from the spin-sdk line. Then run spin build --up again, and it should work.
Meanwhile, we'll work on fixing this so you don't need to edit Cargo.toml. Thanks for reporting this issue!
Probably the best approach here is to use the latest release rather than the HEAD of the Git repo, e.g. git checkout v0.3.0. I'm going to open a PR shortly to change the quickstart instructions to use the tag. I'll also open a new issue for adding an explicit version check to the SDK so we can provide an informative error in cases like this.
When we discussed template version affinity the thought was that we would rev on breaking change (not wait for the release). So tip spin would recognise itself as 0.4.0, look for a 0.4 release of the templates, not find one, and fall back to HEAD.
When we discussed template version affinity the thought was that we would rev on breaking change (not wait for the release). So tip
spinwould recognise itself as 0.4.0, look for a 0.4 release of the templates, not find one, and fall back to HEAD.
The issue we ran into here is that we have tag = "v0.3.0" in the Cargo.toml files for the templates, and we can't just change that to tag = "v0.4.0" without actually creating such a tag, which I assume we don't want to do until we actually create that release. We could just remove the tag = "v0.3.0" entirely, of course, but I wasn't sure if that was the right option either.
In HEAD we can do whatever we need to make the templates compatible with Spin HEAD. grin It does depend on revving the Spin binary immediately there has been a breaking change from the previous release though.
To be clear I am 100% open to reworking this if it's not addressing the requirement in a practical way!
I tried both recommendations above:
- https://github.com/fermyon/spin/issues/615#issuecomment-1176253933
- https://github.com/fermyon/spin/issues/615#issuecomment-1176339066
and could not get the provided http-go template to work. I'm on Linux Mint Cinnamon 20.3:
$ spin -V
spin 0.3.0 (9a49057 2022-07-06)
$ spin build --up
Executing the build command for component test-go: tinygo build -wasm-abi=generic -target=wasi -gc=leaking -no-debug -o main.wasm main.go
Successfully ran the build command for the Spin components.
Serving http://127.0.0.1:3000
Available Routes:
test-go: http://127.0.0.1:3000 (wildcard)
2022-07-07T22:45:09.442778Z ERROR spin_http_engine: Error processing request: invalid discriminant for `option`
2022-07-07T22:45:10.674271Z ERROR spin_http_engine: Error processing request: invalid discriminant for `option`
^C
Any ideas how to get back up and running?
@gmlewis: Please try the following:
cargo uninstall spin-cli
git clone https://github.com/fermyon/spin -b v0.3.0
cd spin
rustup target add wasm32-wasi
cargo install --path .
spin templates install --git https://github.com/fermyon/spin --branch v0.3.0 --update
spin new http-rust spin-hello-world
cd spin-hello-world
spin build
spin up
That should ensure you have the correct Spin version and compatible templates. Then, in another terminal:
curl http://127.0.0.1:3000
@dicej - that worked beautifully. Thank you very much!
Thank you all for the helpful responses.
Closing, but feel free to reopen if there are additional issues related to this.
Thanks!
Hello, This issue is reappearing again in v0.7.1
Steps:
Install
export FERMYON_SPIN_VERSION="v0.7.1"
sudo apt-get install build-essential libssl-dev pkg-config
curl -fsSL https://developer.fermyon.com/downloads/install.sh | bash -s -- -v ${FERMYON_SPIN_VERSION}
sudo mv spin /usr/local/bin/
rustup target add wasm32-wasi
spin templates install --git https://github.com/fermyon/spin
Setup
spin new -o ./interceptor http-rust interceptor
cd interceptor
spin build
spin up
Issue
## Invoke
curl -iX GET http://127.0.0.1:3000
## Err
Serving http://127.0.0.1:3000
Available Routes:
interceptor: http://127.0.0.1:3000 (wildcard)
2023-01-09T18:10:06.156462Z ERROR spin_http: Error processing request: invalid discriminant for `option`
Ok, the issue was the templates. CODE18 :)
I had the templates installed, and not updated to match the spin-sdk version. So after the spin upgrade, the user needs to run
spin templates install --git https://github.com/fermyon/spin --update
or for existing projects
Make sure In the Cargo.toml match the spin sdk tag version with the current spin installation for example:
For FERMYON_SPIN_VERSION := "v0.7.1"
the tag would be:
spin-sdk = { git = "https://github.com/fermyon/spin", tag = "v0.7.1" }