pg: Handle error in custom functions calls.