Skip to content

Function download_file() is suppressing the Response data when error occurs #26056

Description

@quaesitor-scientiam

Describe the bug

Message return error received http code 404 and code value is 0

Reproduction Steps

Have a website return 404 in my test URL does this

Expected Behavior

With proper handling it would return error No image by that name.; code: 404

Current Behavior

Returns Message return error received http code 404 and code value is 0

Possible Solution

Fixed here

pub fn download_file(url string, out_file_path string) ! {
	$if debug_http ? {
		println('http.download_file url=${url} out_file_path=${out_file_path}')
	}
	s := get(url) or { return err }
	if s.status() != .ok {
		// return error('received http code ${s.status_code}')
		return error_with_code(s.body, s.status_code)
	}
	$if debug_http ? {
		println('http.download_file saving ${s.body.len} bytes')
	}
	os.write_file(out_file_path, s.body)!
}

Additional Information/Context

No response

V version

PS S:\Docker> v -v V 0.4.12 fd31771

Environment details (OS name and version, etc.)

|V full version      |V 0.4.12 0800feb35aec2eed8a730858d429dbd9f93a914e.fd31771
|:-------------------|:-------------------
|OS                  |windows, Microsoft Windows 11 Pro 26200 64-bit
|Processor           |24 cpus, 64bit, little endian, AMD Ryzen 9 5900X 12-Core Processor
|Memory              |69.13GB/127.92GB
|                    |
|V executable        |S:\repo\vlang2\v.exe
|V last modified time|2025-12-20 05:50:35
|                    |
|V home dir          |OK, value: S:\repo\vlang2
|VMODULES            |OK, value: C:\Users\john3\.vmodules
|VTMP                |OK, value: S:\temp\v_0
|Current working dir |OK, value: S:\Docker
|                    |
|env VFLAGS          |"-cc gcc -g"
|Git version         |git version 2.52.0.windows.1
|V git status        |weekly.2025.51-37-gfd317711-dirty
|.git/config present |true
|                    |
|cc version          |N/A
|gcc version         |gcc (MinGW-W64 x86_64-ucrt-posix-seh, built by Brecht Sanders, r8) 13.2.0
|clang version       |clang version 20.1.8
|msvc version        |Microsoft (R) C/C++ Optimizing Compiler Version 19.50.35720 for x64
|tcc version         |tcc version 0.9.27 (x86_64 Windows)
|tcc git status      |thirdparty-windows-amd64 b425ac82
|emcc version        |N/A
|glibc version       |N/A

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    BugThis tag is applied to issues which reports bugs.

    Type

    No type
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions