FAQ
Why I am unable to create a temp file? Please see my code below.

You can refer here http://play.golang.org/p/oI4IiXLRfr

or you can view code below.
(both are same)

package main
import "fmt"
import "io/ioutil"

func main() {
tempFile, _ := ioutil.TempFile("/", "postcard_vid")
fmt.Println(tempFile.Name())
}


throws error:

panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x8 pc=0x400c77]

goroutine 1 [running]:
main.main()
/tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8 +0x77


--

Search Discussions

  • Dave Cheney at Sep 19, 2012 at 10:11 pm
    You are discarding the error value returned form ioutil.TempFile. If
    there is an error (and there is good reason to believe there is) then
    you cannot make any assumptions about the value of tempFile.

    Cheers

    Dave
    On Thu, Sep 20, 2012 at 8:07 AM, Jai Kumar wrote:
    Why I am unable to create a temp file? Please see my code below.

    You can refer here http://play.golang.org/p/oI4IiXLRfr

    or you can view code below.
    (both are same)

    package main
    import "fmt"
    import "io/ioutil"

    func main() {
    tempFile, _ := ioutil.TempFile("/", "postcard_vid")
    fmt.Println(tempFile.Name())
    }


    throws error:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x8 pc=0x400c77]

    goroutine 1 [running]:
    main.main()
    /tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8
    +0x77


    --
    --
  • Jai Kumar at Sep 19, 2012 at 10:22 pm
    Thanks. Got it. I checked error and it was permission issue. Thank you. I
    fixed it now. You guys are awesome :)
    On Wednesday, September 19, 2012 3:11:27 PM UTC-7, Dave Cheney wrote:

    You are discarding the error value returned form ioutil.TempFile. If
    there is an error (and there is good reason to believe there is) then
    you cannot make any assumptions about the value of tempFile.

    Cheers

    Dave
    On Thu, Sep 20, 2012 at 8:07 AM, Jai Kumar wrote:
    Why I am unable to create a temp file? Please see my code below.

    You can refer here http://play.golang.org/p/oI4IiXLRfr

    or you can view code below.
    (both are same)

    package main
    import "fmt"
    import "io/ioutil"

    func main() {
    tempFile, _ := ioutil.TempFile("/", "postcard_vid")
    fmt.Println(tempFile.Name())
    }


    throws error:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x8 pc=0x400c77]

    goroutine 1 [running]:
    main.main()
    /tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8
    +0x77


    --
    --
  • Johann Höchtl at Sep 20, 2012 at 7:22 pm

    Am Donnerstag, 20. September 2012 00:15:34 UTC+2 schrieb Jai Kumar:
    Thanks. Got it. I checked error and it was permission issue. Thank you. I
    fixed it now. You guys are awesome :)
    Thanks god it was a permission issue, otherwise you would be executing as
    root which is generally a bad idea.

    On Wednesday, September 19, 2012 3:11:27 PM UTC-7, Dave Cheney wrote:

    You are discarding the error value returned form ioutil.TempFile. If
    there is an error (and there is good reason to believe there is) then
    you cannot make any assumptions about the value of tempFile.

    Cheers

    Dave
    On Thu, Sep 20, 2012 at 8:07 AM, Jai Kumar wrote:
    Why I am unable to create a temp file? Please see my code below.

    You can refer here http://play.golang.org/p/oI4IiXLRfr

    or you can view code below.
    (both are same)

    package main
    import "fmt"
    import "io/ioutil"

    func main() {
    tempFile, _ := ioutil.TempFile("/", "postcard_vid")
    fmt.Println(tempFile.Name())
    }


    throws error:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x8 pc=0x400c77]

    goroutine 1 [running]:
    main.main()
    /tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8
    +0x77


    --
    --
  • Dan Kortschak at Sep 19, 2012 at 10:13 pm
    Have a look at the error.
    On Wed, 2012-09-19 at 15:07 -0700, Jai Kumar wrote:
    Why I am unable to create a temp file? Please see my code below.

    You can refer here http://play.golang.org/p/oI4IiXLRfr

    or you can view code below.
    (both are same)

    package main
    import "fmt"
    import "io/ioutil"

    func main() {
    tempFile, _ := ioutil.TempFile("/", "postcard_vid")
    fmt.Println(tempFile.Name())
    }


    throws error:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x8 pc=0x400c77]

    goroutine 1 [running]:
    main.main()
    /tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8 +0x77

    --
  • Richard Norton at Sep 19, 2012 at 10:44 pm
    Right.

    You don't have permission to write to the root dir (that's what my system reported at any rate).

    Try using "" for the dir string instead of "/"; that should use the system default dir for temp files.

    Richard
    On Sep 19, 2012, at 5:12 PM, Dan Kortschak wrote:

    Have a look at the error.
    On Wed, 2012-09-19 at 15:07 -0700, Jai Kumar wrote:
    Why I am unable to create a temp file? Please see my code below.

    You can refer here http://play.golang.org/p/oI4IiXLRfr

    or you can view code below.
    (both are same)

    package main
    import "fmt"
    import "io/ioutil"

    func main() {
    tempFile, _ := ioutil.TempFile("/", "postcard_vid")
    fmt.Println(tempFile.Name())
    }


    throws error:

    panic: runtime error: invalid memory address or nil pointer dereference
    [signal 0xb code=0x1 addr=0x8 pc=0x400c77]

    goroutine 1 [running]:
    main.main()
    /tmpfs/gosandbox-0656bfdd_990cb295_da1c8f79_6e849913_24d9a636/prog.go:8 +0x77

    --
    --

Related Discussions

Discussion Navigation
viewthread | post
Discussion Overview
groupgolang-nuts @
categoriesgo
postedSep 19, '12 at 10:07p
activeSep 20, '12 at 7:22p
posts6
users5
websitegolang.org

People

Translate

site design / logo © 2022 Grokbase