I've a geoprocessing script that I'm trying to get working. I've turned on Show Messages, so I can see how far in the script I've gotten before the submitted job fails, but it's not helping, as I'm getting errors that I don't understand exactly, because I don't know where they occurred. Is there any way to debug server geoprocessing scripts on the server?
EDIT:
Error is occurring in this code, which worked fine locally. I'm not getting either of the messages returned, so something seems to be going wrong with the layers.
for layer in mxdLayers:
try:
arcpy.AddMessage("Layer name is %s" % (layer.name))
layer.visible = visibleLayers[layer.name]
except:
arcpy.AddMessage("Layer not set: " + layer.name)
Error message is Layer: Unexpected error
Edit 2:
The error is not in the code above. The following code takes the parameter and stores the passed in features in a scratch gdb. Currently this is passed as an empty string, as I haven't gotten to testing this part yet.
# Get the passed point graphics and save to scratch workspace
inPointFset = arcpy.GetParameterAsText(9)
if inPointFset == '#' or not inPointFset:
inPointFset = None
else:
arcpy.CopyFeatures_management(inPointFset, os.path.join(arcpy.env.scratchWorkspace, r"scratch.gdb\Points"))
This code then changes the data source of the first mxd layer (which is why it's blowing up; the first layer doesn't reference the points feature class in the scratch gdb), but since the parameter was an empty string, I'm not sure why this is evaluating to true.
mxdLayers = arcpy.mapping.ListLayers(mapDoc)
if inPointFset:
arcpy.AddMessage("Points")
mxdLayers[0].replaceDataSource(os.path.join(arcpy.env.scratchWorkspace, r"scratch.gdb"), "FILEGDB_WORKSPACE", "Points")
Best Answer
I typically use a simple error handling class:
Then I reference it in a try except clause.
This way if any of my code errors it will give me a line number and explanation of the error.