R
RunPod9mo ago
papanton

Serverless not returning error

The following code:
def handler(event):
try:
logger.info('validating input')
validated_input = validate(event['input'], INPUT_SCHEMA)
text = "Here is my input: {}".format(validated_input)
logger.info(text)
if 'errors' in validated_input:
return {
'error': validated_input['errors']
}
logger.info('running inferance')
data = inferance_api(validated_input['validated_input'])
def handler(event):
try:
logger.info('validating input')
validated_input = validate(event['input'], INPUT_SCHEMA)
text = "Here is my input: {}".format(validated_input)
logger.info(text)
if 'errors' in validated_input:
return {
'error': validated_input['errors']
}
logger.info('running inferance')
data = inferance_api(validated_input['validated_input'])
is returning the following logs:
Failed to return job results. | 400, message='Bad Request', url=URL('https://api.runpod.ai/v2/66w85qdd7bcp4t/job-done/8i26p55unhx4my/6843025a-7bbb-48ad-9da3-1b7b569c8d84-e1?gpu=NVIDIA+RTX+A5000&isStream=false')
Failed to return job results. | 400, message='Bad Request', url=URL('https://api.runpod.ai/v2/66w85qdd7bcp4t/job-done/8i26p55unhx4my/6843025a-7bbb-48ad-9da3-1b7b569c8d84-e1?gpu=NVIDIA+RTX+A5000&isStream=false')
No description
No description
5 Replies
ashleyk
ashleyk9mo ago
The error key can only accept str and not a list or dict. Correct way of handling errors and causing the job to fail: If the error is a string:
return {
"error": f"An error occurred while processing the job: {e}"
}
return {
"error": f"An error occurred while processing the job: {e}"
}
If its a list or dict:
return {
"error": f"Some error message",
"output": someDict | someList
}
return {
"error": f"Some error message",
"output": someDict | someList
}
You can also do something like this:
return {
'error': '\n'.join(validated_input['errors'])
}
return {
'error': '\n'.join(validated_input['errors'])
}
But the way you're doing it is incorrect. @Justin Merrell can't this be fixed in SDK? More and more people are having this issue, including me.
Justin Merrell
Justin Merrell9mo ago
I'll take a look, I thought I was just converting any error into a string as of now.
ashleyk
ashleyk9mo ago
Oh maybe it does, I haven't checked out the latest SDK version, but it was an issue for me.
papanton
papantonOP9mo ago
your fix worked @ashleyk thank you! not sure why my docker file bundled an old runpod version - the same code runs on a different serverless endpoint
ashleyk
ashleyk9mo ago
Probably running an older SDK version, at some point returning a list for error worked but then somewhere along the line it stopped working.
Want results from more Discord servers?
Add your server