vlang

router raise error for any other route than slash


CONTEXT

I have this program in src/index.v

import vweb

struct App {
    vweb.Context
}

["/"]
pub fn (mut app App) home_index() vweb.Result {
    return app.html("home")
}

["/about"]
pub fn (mut app App) about_index() vweb.Result {
    return app.html("about")
}

fn main() {
    vweb.run<App>(80)
}

And I run this command to compile it

v -o dist/index src/index.v

And when I run this command the server is up

./dist/index

PROBLEM

When I browse http://localhost, I see the home text, but when I browse http://localhost/about, I see this error printed in my console:

./dist/index
[Vweb] Running app on http://localhost:80
V panic: array.get: index out of range (i == -1, a.len == 0)
v hash: b3890e2
C.backtrace returned less than 2 frames

I noted that if I remove the home route code block, no error is raised (but I do not know how to display a response when the "/" route is found for the moment).

QUESTION

Does anyone knows why this error occurs?

NOTES

My v version

v --version
V 0.2.2 b3890e2

My OS version

cat /etc/issue
Welcome to Alpine Linux 3.11

Gcc version

gcc --version
gcc (Alpine 9.3.0) 9.3.0

Solution

  • This is a bug in the framwork vweb. It's being addressed in PR #10001.