v icon indicating copy to clipboard operation
v copied to clipboard

[new_veb] Run error

Open Avey777 opened this issue 3 months ago • 3 comments

Describe the bug

new_veb run error

Reproduction Steps

import veb

struct Context {
	veb.Context
}

struct App {
	veb.Middleware[Context]
}

fn (mut app App) index(mut ctx Context) veb.Result {
	return ctx.json('index succcess')
}

fn main() {
	port := 9008
	mut app := &App{}
	app.use(authority_middleware())
	veb.run[App, Context](mut app, port)
}

fn authority_middleware() veb.MiddlewareOptions[Context] {
	return veb.MiddlewareOptions[Context]{
		handler: authority_jwt_verify
		after:   false
	}
}

fn authority_jwt_verify(mut ctx Context) bool {
	// ctx.res.set_status(.unauthorized)
	// ctx.res.header.set(.content_type, 'application/json')
	ctx.send_response_to_client('application/json', 'send_response_to_client unauthorized')
	// ctx.request_error('request_error')
	// ctx.server_error('server_error')

	ctx.error('Bad credentials')
	return false
}

v -d new_veb run .

Expected Behavior

[veb] Running app on http://localhost:9008/

Current Behavior

/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:9:8: warning: module 'net' is imported but never used
    7 | import net.http
    8 | import time
    9 | import net
      |        ~~~
   10 | import net.urllib
   11 | import os
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:11:8: warning: module 'os' is imported but never used
    9 | import net
   10 | import net.urllib
   11 | import os
      |        ~~
   12 |
   13 | struct RequestParams {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_picoev.v:3:8: warning: module 'os' is imported but never used
    1 | module veb
    2 |
    3 | import os
      |        ~~
    4 |
    5 | $if !new_veb ? {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:6:8: warning: module 'os' is imported but never used
    4 | module fasthttp
    5 |
    6 | import os
      |        ~~
    7 | import time
    8 | import term
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:7:8: warning: module 'time' is imported but never used
    5 |
    6 | import os
    7 | import time
      |        ~~~~
    8 | import term
    9 | import net
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:8:8: warning: module 'term' is imported but never used
    6 | import os
    7 | import time
    8 | import term
      |        ~~~~
    9 | import net
   10 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:9:8: warning: module 'net' is imported but never used
    7 | import time
    8 | import term
    9 | import net
      |        ~~~
   10 |
   11 | #include <sys/types.h>
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:132:13: warning: unknown type `C.pthread_cond_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_t`?
  130 | mut:
  131 |     task_mutex C.pthread_mutex_t
  132 |     task_cond  C.pthread_cond_t
      |                ~~~~~~~~~~~~~~~~
  133 |     task_head  &Task = unsafe { nil }
  134 |     task_tail  &Task = unsafe { nil }
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:150:18: warning: unknown type `C.pthread_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_cond_t`?
  148 |     request_handler fn (req HttpRequest) ![]u8 = unsafe { nil }
  149 |     worker_data     WorkerData
  150 |     threads         [num_threads]C.pthread_t
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~
  151 | }
  152 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:220:5: warning: function `C.snprintf` must be called from an `unsafe` block
  218 |         // Copy the body with headers to done.resp
  219 |         resp := C.malloc(buf_size)
  220 |         C.snprintf(resp, buf_size, c'%s', body_with_headers.str)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  221 |         len := body_with_headers.len
  222 |         // println('GGGG len=${len} body.len=${body.len} full body len = ${body_with_headers.len}')
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:79:2: warning: unused variable: `req_bytes`
   77 |     path := unsafe { tos(req.path.buf, req.path.len) }
   78 |     println('path=${path}')
   79 |     req_bytes := req.buffer
      |     ~~~~~~~~~
   80 |     client_fd := req.client_conn_fd
   81 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:42:11: warning: cannot assign a reference to a value (this will be an error soon) left=veb.RequestParams false right=veb.RequestParams true ptr=true
   40 |     controllers_sorted := check_duplicate_routes_in_controllers[A](global_app, routes)!
   41 |     unsafe {
   42 |         gparams = &RequestParams{
      |                 ^
   43 |             global_app:         global_app
   44 |             controllers_sorted: controllers_sorted
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:312:22: error: cannot assign to `addr.sin_family`: expected `u16`, not `int`
  310 |     mut addr := C.sockaddr_in{}
  311 |     C.memset(&addr, 0, sizeof(addr))
  312 |     addr.sin_family = C.AF_INET
      |                         ~~~~~~~
  313 |     // addr.sin_addr = u32(0) // C.htons(C.INADDR_ANY))
  314 |     addr.sin_port = u16(C.htons(u16(s.port)))

Possible Solution

No response

Additional Information/Context

No response

V version

V 0.4.12 ac2e7d

Environment details (OS name and version, etc.)

V full version V 0.4.12 9a0166701c2fc7095bed34299b976167ce03b791.ac2e7d7
OS linux, Deepin 25
Processor 6 cpus, 64bit, little endian, Intel(R) Core(TM) i5-8500B CPU @ 3.00GHz
Memory 0.34GB/7.6GB
V executable /home/Jengro/.vmr/versions/v_versions/v_latest/v
V last modified time 2025-10-26 10:15:40
V home dir OK, value: /home/Jengro/.vmr/versions/v_versions/v_latest
VMODULES OK, value: /home/Jengro/.vmodules
VTMP OK, value: /tmp/v_1000
Current working dir OK, value: /home/Jengro
Git version git version 2.50.1
V git status weekly.2025.29-529-gac2e7d7f
.git/config present true
cc version cc (Deepin 12.3.0-17deepin15) 12.3.0
gcc version gcc (Deepin 12.3.0-17deepin15) 12.3.0
clang version Deepin clang version 17.0.6 (5deepin5)
tcc version tcc version 0.9.28rc 2025-02-13 HEAD@f8bd136d (x86_64 Linux)
tcc git status thirdparty-linux-amd64 696c1d84
emcc version N/A
glibc version ldd (Debian GLIBC 2.38-6deepin16) 2.38

[!NOTE] You can use the 👍 reaction to increase the issue's priority for developers.

Please note that only the 👍 reaction to the issue itself counts as a vote. Other reactions and those to comments will not be taken into account.

Avey777 avatar Oct 26 '25 11:10 Avey777

watching

X1aSheng avatar Oct 29 '25 02:10 X1aSheng

builder error: Header file <sys/event.h>, needed for modulefasthttpwas not found. Please install the corresponding development headers.

Is this currently only available on Mac systems and using <sys/epoll. h> on Linux systems

Avey777 avatar Oct 31 '25 00:10 Avey777

https://github.com/vlang/v/commit/73cc80229de6dbcb2f378574014316fd06db0288 @medvednikov

linux

v -d new_veb -d -show-c-output -o app  .
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:9:8: warning: module 'net' is imported but never used
    7 | import net.http
    8 | import time
    9 | import net
      |        ~~~
   10 | import net.urllib
   11 | import os
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:11:8: warning: module 'os' is imported but never used
    9 | import net
   10 | import net.urllib
   11 | import os
      |        ~~
   12 |
   13 | struct RequestParams {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_picoev.v:3:8: warning: module 'os' is imported but never used
    1 | module veb
    2 |
    3 | import os
      |        ~~
    4 |
    5 | $if !new_veb ? {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:6:8: warning: module 'os' is imported but never used
    4 | module fasthttp
    5 |
    6 | import os
      |        ~~
    7 | import time
    8 | import term
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:7:8: warning: module 'time' is imported but never used
    5 |
    6 | import os
    7 | import time
      |        ~~~~
    8 | import term
    9 | import net
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:8:8: warning: module 'term' is imported but never used
    6 | import os
    7 | import time
    8 | import term
      |        ~~~~
    9 | import net
   10 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:9:8: warning: module 'net' is imported but never used
    7 | import time
    8 | import term
    9 | import net
      |        ~~~
   10 |
   11 | #include <sys/types.h>
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:121:13: warning: unknown type `C.pthread_cond_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_t`?
  119 | mut:
  120 |     task_mutex C.pthread_mutex_t
  121 |     task_cond  C.pthread_cond_t
      |                ~~~~~~~~~~~~~~~~
  122 |     task_head  &Task = unsafe { nil }
  123 |     task_tail  &Task = unsafe { nil }
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:139:18: warning: unknown type `C.pthread_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_cond_t`?
  137 |     request_handler fn (req HttpRequest) ![]u8 = unsafe { nil }
  138 |     worker_data     WorkerData
  139 |     threads         [num_threads]C.pthread_t
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~
  140 | }
  141 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:187:5: warning: function `C.snprintf` must be called from an `unsafe` block
  185 |         body_with_headers := body.bytestr()
  186 |         resp := C.malloc(buf_size)
  187 |         C.snprintf(resp, buf_size, c'%s', body_with_headers.str)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188 |         len := body_with_headers.len
  189 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp_linux.v:161:32: warning: reading a union field (or its address) requires `unsafe`
  159 |         for i := 0; i < nev; i++ {
  160 |             event := events[i]
  161 |             ptr_val := isize(event.data.ptr)
      |                                         ~~~
  162 |
  163 |             // 1. Check for Listener Socket
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:79:2: warning: unused variable: `req_bytes`
   77 |     path := unsafe { tos(req.path.buf, req.path.len) }
   78 |     println('path=${path}')
   79 |     req_bytes := req.buffer
      |     ~~~~~~~~~
   80 |     client_fd := req.client_conn_fd
   81 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:42:11: warning: cannot assign a reference to a value (this will be an error soon) left=veb.RequestParams false right=veb.RequestParams true ptr=true
   40 |     controllers_sorted := check_duplicate_routes_in_controllers[A](global_app, routes)!
   41 |     unsafe {
   42 |         gparams = &RequestParams{
      |                 ^
   43 |             global_app:         global_app
   44 |             controllers_sorted: controllers_sorted
================== C compilation error (from tcc): ==============
cc: /tmp/v_1000/app.01KAJAXJ528MVFR8BMZ9R6YR71.tmp.c:14651: error: field not found: task_head
=================================================================
(You can pass `-cg`, or `-show-c-output` as well, to print all the C error messages).
builder error:
==================
C error found. It should never happen, when compiling pure V code.
This is a V compiler bug, please report it using `v bug file.v`,
or goto https://github.com/vlang/v/issues/new/choose .
You can also use #help on Discord: https://discord.gg/vlang .
v -prod -d new_veb -d -show-c-output -o app  .
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:9:8: warning: module 'net' is imported but never used
    7 | import net.http
    8 | import time
    9 | import net
      |        ~~~
   10 | import net.urllib
   11 | import os
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:11:8: warning: module 'os' is imported but never used
    9 | import net
   10 | import net.urllib
   11 | import os
      |        ~~
   12 |
   13 | struct RequestParams {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_picoev.v:3:8: warning: module 'os' is imported but never used
    1 | module veb
    2 |
    3 | import os
      |        ~~
    4 |
    5 | $if !new_veb ? {
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:6:8: warning: module 'os' is imported but never used
    4 | module fasthttp
    5 |
    6 | import os
      |        ~~
    7 | import time
    8 | import term
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:7:8: warning: module 'time' is imported but never used
    5 |
    6 | import os
    7 | import time
      |        ~~~~
    8 | import term
    9 | import net
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:8:8: warning: module 'term' is imported but never used
    6 | import os
    7 | import time
    8 | import term
      |        ~~~~
    9 | import net
   10 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:9:8: warning: module 'net' is imported but never used
    7 | import time
    8 | import term
    9 | import net
      |        ~~~
   10 |
   11 | #include <sys/types.h>
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:121:13: error: unknown type `C.pthread_cond_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_t`?
  119 | mut:
  120 |     task_mutex C.pthread_mutex_t
  121 |     task_cond  C.pthread_cond_t
      |                ~~~~~~~~~~~~~~~~
  122 |     task_head  &Task = unsafe { nil }
  123 |     task_tail  &Task = unsafe { nil }
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:139:18: error: unknown type `C.pthread_t` (all virtual C types must be defined, this will be an error soon).
Did you mean `C.pthread_cond_t`?
  137 |     request_handler fn (req HttpRequest) ![]u8 = unsafe { nil }
  138 |     worker_data     WorkerData
  139 |     threads         [num_threads]C.pthread_t
      |                     ~~~~~~~~~~~~~~~~~~~~~~~~
  140 | }
  141 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp.v:187:5: error: function `C.snprintf` must be called from an `unsafe` block
  185 |         body_with_headers := body.bytestr()
  186 |         resp := C.malloc(buf_size)
  187 |         C.snprintf(resp, buf_size, c'%s', body_with_headers.str)
      |           ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
  188 |         len := body_with_headers.len
  189 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/fasthttp/fasthttp_linux.v:161:32: error: reading a union field (or its address) requires `unsafe`
  159 |         for i := 0; i < nev; i++ {
  160 |             event := events[i]
  161 |             ptr_val := isize(event.data.ptr)
      |                                         ~~~
  162 |
  163 |             // 1. Check for Listener Socket
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:79:2: error: unused variable: `req_bytes`
   77 |     path := unsafe { tos(req.path.buf, req.path.len) }
   78 |     println('path=${path}')
   79 |     req_bytes := req.buffer
      |     ~~~~~~~~~
   80 |     client_fd := req.client_conn_fd
   81 |
/home/Jengro/.vmr/versions/v_versions/v_latest/vlib/veb/veb_d_new_veb.v:42:11: error: cannot assign a reference to a value (this will be an error soon) left=veb.RequestParams false right=veb.RequestParams true ptr=true
   40 |     controllers_sorted := check_duplicate_routes_in_controllers[A](global_app, routes)!
   41 |     unsafe {
   42 |         gparams = &RequestParams{
      |                 ^
   43 |             global_app:         global_app
   44 |             controllers_sorted: controllers_sorted

Avey777 avatar Nov 21 '25 03:11 Avey777