thedevsaddam / gojsonq

A simple Go package to Query over JSON/YAML/XML/CSV Data
https://github.com/thedevsaddam/gojsonq/wiki
MIT License
2.17k stars 140 forks source link

Add more error info on As() function #72

Closed cifren closed 4 years ago

cifren commented 4 years ago

issue

When using :

tempTags = []Tag{} // Structure
jsonResult.As(&tempTags)

This error is displayed an error from reflect library:

panic: reflect: call of reflect.Value.Call on zero Value [recovered]
        panic: reflect: call of reflect.Value.Call on zero Value

Expected

Should display a more specific error that give us more clues in order to understand what is going on

Panic: the method '*[]repository.Tag' must be part of 'map[*[]bool:BoolSlice *[]float32:Float32Slice *[]float64:Float64Slice *[]int:IntSlice *[]int16:Int16Slice *[]int32:Int32Slice *[]int8:Int8Slice *[]string:StringSlice *[]time.Duration:DurationSlice *[]uint:UintSlice *[]uint16:Uint16Slice *[]uint32:Uint32Slice *[]uint8:Uint8Slice *bool:Bool *float32:Float32 *float64:Float64 *int:Int *int16:Int16 *int32:Int32 *int8:Int8 *string:String *time.Duration:Duration *uint:Uint *uint16:Uint16 *uint32:Uint32 *uint8:Uint8]' [recovered]
        panic: the method '*[]repository.Tag' must be part of 'map[*[]bool:BoolSlice *[]float32:Float32Slice *[]float64:Float64Slice *[]int:IntSlice *[]int16:Int16Slice *[]int32:Int32Slice *[]int8:Int8Slice *[]string:StringSlice *[]time.Duration:DurationSlice *[]uint:UintSlice *[]uint16:Uint16Slice *[]uint32:Uint32Slice *[]uint8:Uint8Slice *bool:Bool *float32:Float32 *float64:Float64 *int:Int *int16:Int16 *int32:Int32 *int8:Int8 *string:String *time.Duration:Duration *uint:Uint *uint16:Uint16 *uint32:Uint32 *uint8:Uint8]'
coveralls commented 4 years ago

Pull Request Test Coverage Report for Build 345


Changes Missing Coverage Covered Lines Changed/Added Lines %
result.go 1 2 50.0%
<!-- Total: 1 2 50.0% -->
Totals Coverage Status
Change from base Build 341: -0.08%
Covered Lines: 10440
Relevant Lines: 10488

💛 - Coveralls
cifren commented 4 years ago

I am not sure if I understand that coverage message... can you explain ?

Dragomir-Ivanov commented 4 years ago

Hi @cifren Sorry for the late response. You should add test case that tests the code branch you added. In your particular case is to add test case where methodMap[method] is empty, e.g. =="".

thedevsaddam commented 4 years ago

@cifren You must create an issue and discuss it with others about the problem before sending PR.

I think we can add an error and stop panicking

https://github.com/thedevsaddam/gojsonq/blob/master/CONTRIBUTING.md

thedevsaddam commented 4 years ago

@cifren I fixed the issue. Please update the package to v2.5.0

and closing the PR.

Thank you :)

cifren commented 4 years ago

You are right panicking was a little too much, an error is better.

Thank you for your help.