go-force
go-force copied to clipboard
better error handling when custom sobject is not found
Today if you attempt to interact with an SObject that doesn't exist in SalesForce the force package will panic.
panic: runtime error: invalid memory address or nil pointer dereference
[signal 0xb code=0x1 addr=0x48 pc=0x49f87]
goroutine 16 [running]:
runtime.panic(0x2a48a0, 0x4638e4)
/usr/local/Cellar/go/1.3.3/libexec/src/pkg/runtime/panic.c:279 +0xf5
github.com/nimajalali/go-force/force.(*ForceApi).GetSObject(0xc208004180, 0x2eba50, 0xe, 0x51def0, 0xc208210000, 0x0, 0x0)
/Users/njalali/Documents/go/src/github.com/nimajalali/go-force/force/sobjects.go:68 +0x137
Instead of a panic we should return a meaningful error. To do this we should verify the object metadata exists in the forceApi.apiSObjects map before trying to access it.
e.g.
data, ok := forceApi.apiSObjects["SOME_OBJECT_NAME"]
if !ok {
return fmt.Errorf("Unable to find metadata for object: %s", "SOME_OBJECT_NAME")
}