Skip to content

Commit ae6ec70

Browse files
committed
Fix blackd returning 500 for invalid f-strings
When blackd receives code with invalid f-strings (e.g. f"{}"), ast.parse() raises ASTSafetyError. This fell through to the generic except Exception handler, returning HTTP 500. Add specific handler to return HTTP 400. Fixes #3616
1 parent e079b7e commit ae6ec70

File tree

1 file changed

+2
-0
lines changed

1 file changed

+2
-0
lines changed

src/blackd/__init__.py

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -206,6 +206,8 @@ async def handle(
206206
return web.Response(status=204, headers=headers)
207207
except black.InvalidInput as e:
208208
return web.Response(status=400, headers=headers, text=str(e))
209+
except black.parsing.ASTSafetyError as e:
210+
return web.Response(status=400, headers=headers, text=str(e))
209211
except web.HTTPException:
210212
raise
211213
except Exception as e:

0 commit comments

Comments
 (0)