You’re getting an error on the file read. Print the error to see what it is, 
instead of a hardcoded string.

On 16 Mar 2018, at 08:24, dev.ys084...@gmail.com<mailto:dev.ys084...@gmail.com> 
wrote:


Recently I started to use golang in project and I got one problem.
The problem is the result of yaml.Unmarshal when I put invalid yaml is 
different between osX and linux.

My environments are here

macOS Sierra 10.12.6
go version go1.10 darwin/amd64

Linux version 3.10.0-693.11.6.el7.x86_64
go version go1.10 linux/amd64


This is my code I ran.

invalid.yaml:

---------------------------------------------------------
  namespace: aaaa
name: bbbbbbb
 description:  hyoooooooooooooooooooooooo
maintainer: du...@example.com<mailto:du...@example.com>
version: 1.1.1
format::
  :type: sample
  file: ./foo.sh


---------------------------------------------------------

main.go:

---------------------------------------------------------

package main import ( "fmt" "io/ioutil" "os" yaml 
"gopkg.in/yaml.v2<http://gopkg.in/yaml.v2>" ) type Sample struct { Namespace 
string `yaml:"namespace"` Name string `yaml:"name"` Description string 
`yaml:"description"` Maintainer string `yaml:"maintainer"` Version string 
`yaml:"version"` Format struct { Type string `yaml:"type"` File string 
`yaml:"file"` } `yaml:"format"` } const ( validYaml = "./valid.yaml" 
invalidYaml = "./invalid.yaml" ) func main() { data2, err := 
ioutil.ReadFile(invalidYaml) if err != nil { fmt.Println("It will not come here 
2") os.Exit(1) } sample2 := &Sample{} err = yaml.Unmarshal(data2, sample2) if 
err != nil { fmt.Println("Should come here") os.Exit(0) } fmt.Println("It will 
not come here!!!!!!") os.Exit(1) }

---------------------------------------------------------

Expect to see osX "Should come here"

linux
"Should come here"

See instead
osX
"Should come here"
linux
"It will not come here!!!!!!"

First time I thought this is a problem of library but the library looks like 
does not have the difference between linux and osX.
So I ask this problem here.


I hope to fix this problem.

Thank you


Yuichi

--
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to 
golang-nuts+unsubscr...@googlegroups.com<mailto:golang-nuts+unsubscr...@googlegroups.com>.
For more options, visit https://groups.google.com/d/optout.

-- 
You received this message because you are subscribed to the Google Groups 
"golang-nuts" group.
To unsubscribe from this group and stop receiving emails from it, send an email 
to golang-nuts+unsubscr...@googlegroups.com.
For more options, visit https://groups.google.com/d/optout.

Reply via email to