Skip to content

bugfix: panic when type unmatch between toml and struct#236

Merged
pelletier merged 3 commits intopelletier:masterfrom
jayi:master
Sep 18, 2018
Merged

bugfix: panic when type unmatch between toml and struct#236
pelletier merged 3 commits intopelletier:masterfrom
jayi:master

Conversation

@jayi
Copy link
Copy Markdown
Contributor

@jayi jayi commented Aug 16, 2018

When type unmatch between toml and struct, will panic.

Example:

type Postgres struct {
	Id int64
}
type Config struct {
	Postgres Postgres
}

doc := []byte(`
[Postgres]
Id = 1e3
`)

config := Config{}
toml.Unmarshal(doc, &config)
fmt.Println("id=", config.Postgres.Id)

Panic:

panic: reflect: call of reflect.Value.Int on float64 Value [recovered]
	panic: reflect: call of reflect.Value.Int on float64 Value

@codecov
Copy link
Copy Markdown

codecov bot commented Aug 16, 2018

Codecov Report

Merging #236 into master will not change coverage.
The diff coverage is 0%.

Impacted file tree graph

@@           Coverage Diff           @@
##           master     #236   +/-   ##
=======================================
  Coverage   88.47%   88.47%           
=======================================
  Files           9        9           
  Lines        1649     1649           
=======================================
  Hits         1459     1459           
  Misses        135      135           
  Partials       55       55
Impacted Files Coverage Δ
marshal.go 86.5% <0%> (ø) ⬆️

Continue to review full report at Codecov.

Legend - Click here to learn more
Δ = absolute <relative> (impact), ø = not affected, ? = missing data
Powered by Codecov. Last update c2dbbc2...2484e4d. Read the comment docs.

@pelletier
Copy link
Copy Markdown
Owner

Thanks for your PR! Looks like it's also gonna help with #219! I pulled your changes and tried with the example you gave, but I'm getting config.Postgres.Id equal to 0. That doesn't seem like the expected output?

@jayi
Copy link
Copy Markdown
Contributor Author

jayi commented Aug 28, 2018

id= 1000

This is the output I got, it seems ok?

@pelletier
Copy link
Copy Markdown
Owner

Interesting. With

type Postgres struct {
	Id int64
}
type Config struct {
	Postgres Postgres
}

doc := []byte(`
[Postgres]
Id = 1e3
`)

config := Config{}
toml.Unmarshal(doc, &config)

fmt.Println("id=", config.Postgres.Id)

I get id= 0. Which version of go are you using?

@jayi
Copy link
Copy Markdown
Contributor Author

jayi commented Aug 28, 2018

1.9.2

@pelletier pelletier merged commit e33f654 into pelletier:master Sep 18, 2018
@pelletier
Copy link
Copy Markdown
Owner

Thanks! Sorry took so long to merge that. I was actually doing something silly, the patch works well.

@jayi
Copy link
Copy Markdown
Contributor Author

jayi commented Sep 21, 2018

Thank you!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants