Skip to content

Commit c12c5d1

Browse files
chrisrink10Christopher Rink
andauthored
Stop chaining macroexpansion exceptions during compilation (#853)
Fixes #852 --------- Co-authored-by: Christopher Rink <[email protected]>
1 parent 8b3a2da commit c12c5d1

File tree

2 files changed

+11
-2
lines changed

2 files changed

+11
-2
lines changed

CHANGELOG.md

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9,6 +9,9 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
99
* Added filename metadata to compiler exceptions (#844)
1010
* Added a compile-time warning for attempting to call a function with an unsupported number of arguments (#671)
1111

12+
### Changed
13+
* Cause exceptions arising from compilation issues during macroexpansion will no longer be nested for each level of macroexpansion (#852)
14+
1215
### Fixed
1316
* Fix a bug where `basilisp.lang.compiler.exception.CompilerException` would nearly always suppress line information in it's `data` map (#845)
1417
* Fix a bug where the function returned by `partial` retained the meta, arities, and `with_meta` method of the wrapped function rather than creating new ones (#847)

src/basilisp/lang/compiler/analyzer.py

Lines changed: 8 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -806,10 +806,10 @@ def _call_args_ast(
806806

807807
kw_map[munged_k] = _analyze_form(v, ctx)
808808

809-
except ValueError:
809+
except ValueError as e:
810810
raise ctx.AnalyzerException(
811811
"keyword arguments must appear in key/value pairs", form=form
812-
) from ValueError
812+
) from e
813813
else:
814814
kwargs = lmap.map(kw_map)
815815
else:
@@ -2509,6 +2509,12 @@ def _invoke_ast(form: Union[llist.PersistentList, ISeq], ctx: AnalyzerContext) -
25092509
expanded = fn.var.value(macro_env, form, *form.rest)
25102510
return __handle_macroexpanded_ast(form, expanded, ctx)
25112511
except Exception as e:
2512+
if isinstance(e, CompilerException) and ( # pylint: disable=no-member
2513+
e.phase == CompilerPhase.MACROEXPANSION
2514+
):
2515+
# Do not chain macroexpansion exceptions since they don't
2516+
# actually add anything of value over the cause exception
2517+
raise
25122518
raise CompilerException(
25132519
"error occurred during macroexpansion",
25142520
filename=ctx.filename,

0 commit comments

Comments
 (0)