Skip to content

Malformed error messages from db.mysql real_query fail encoding to json #19842

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
einar-hjortdal opened this issue Nov 11, 2023 · 0 comments
Open
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Nicer V Errors Bugs/feature requests, related to improving V error messages.

Comments

@einar-hjortdal
Copy link
Contributor

einar-hjortdal commented Nov 11, 2023

Describe the bug

Error messages are malformed, causing json.encode quiet failures

struct CustomError {
	message   string
	code      int
	data      string
	timestamp string
}

pub fn (e CustomError) code() int {
	return e.code
}

pub fn (e CustomError) msg() string {
	return e.message
}

const error_codes = {
	500: 'Internal Server Error'
}

fn new_custom_error(code int, data string) CustomError {
	return CustomError{
		message: utils.error_codes[code]
		code: code
		data: data
		timestamp: time.now().format_rfc3339()
	}
}

// in an `or` block when `db.mysql` `real_query` returns an error
new_custom_error(500, err.msg())

println(err.msg())
println(new_custom_error)
println(json.encode(new_custom_error))

Outputs

ncorrect string value: 'undefined' for function uuid_to_bin; code: 1411
CustomError{
    message: 'Internal Server Error'
    code: 500
    data: 'ncorrect string value: 'undefined' for function uuid_to_bin; code: 1411'
    timestamp: '2023-11-10T21:26:39.884Z'
}
{"message":"Internal Server Error","code":500,"data":"","timestamp":"2023-11-10T21:26:39.884Z"}

Reproduction Steps

You would have to run the code above and receive error messages from db.mysql real_query.

Because of the nature of this bug, setting up mysql is needed for rull repro

Expected Behavior

json.encode encodes the error string correctly

Current Behavior

json.encode replaces error string with empty string

Possible Solution

db.mysql errors should escape characters correctly.
json.encode should throw a warning or something at runtime when a string is encoded to an empty string

Additional Information/Context

No response

V version

Current V version: V 0.4.2 e7cad4f, timestamp: 2023-11-11 01:10:34 +0300

Environment details (OS name and version, etc.)

V full version: V 0.4.2 95509cf.e7cad4f
OS: linux, Linux version 5.14.0-284.30.1.el9_2.x86_64 (mockbuild@mj.euro.kojibuilder106) (gcc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4), GNU ld version 2.35.2-37.el9) #1 SMP PREEMPT_DYNAMIC Fri Sep 15 08:06:33 UTC 2023
Processor: 8 cpus, 64bit, little endian, Intel(R) Core(TM) i7-4790K CPU @ 4.00GHz

getwd: /home/coachonko/Documents/projects/vlang/peony
vexe: /home/coachonko/.local/lib64/v/v
vexe mtime: 2023-11-11 07:03:30

vroot: OK, value: /home/coachonko/.local/lib64/v
VMODULES: OK, value: /home/coachonko/.vmodules
VTMP: OK, value: /tmp/v_1000

Git version: git version 2.39.3
Git vroot status: weekly.2023.44-99-ge7cad4f5
.git/config present: true

CC version: cc (GCC) 11.3.1 20221121 (Red Hat 11.3.1-4)
thirdparty/tcc status: thirdparty-linux-amd64 12f392c3

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.

@einar-hjortdal einar-hjortdal added the Bug This tag is applied to issues which reports bugs. label Nov 11, 2023
@ArtemkaKun ArtemkaKun added Nicer V Errors Bugs/feature requests, related to improving V error messages. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. labels Nov 11, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug This tag is applied to issues which reports bugs. Modules: JSON Bugs/feature requests, that are related to `json` and `x.json2` modules. Nicer V Errors Bugs/feature requests, related to improving V error messages.
Projects
None yet
Development

No branches or pull requests

2 participants