Skip to content

Commit 7f9ba87

Browse files
BloggerBustjayanth-kumar-morem
authored andcommitted
fix(workflow): avoid redundant file I/O when resolving callsite source
Previously, the `Atom` class attempted to reread the source file to retrieve callsite source code during runtime error reporting. This fallback logic is now commented out to prevent repeated file reads, which can be inefficient and unnecessary. A `TODO` comment has been added to centralize line buffer access in the service layer. In the meantime, if `callsite_source` is missing, it will simply be omitted rather than triggering another file read. Also updated `register_error(...)` to explicitly include the `source` field, defaulting to an empty string when unavailable.
1 parent 5a37c2b commit 7f9ba87

File tree

1 file changed

+16
-10
lines changed

1 file changed

+16
-10
lines changed

preswald/interfaces/workflow.py

Lines changed: 16 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -176,21 +176,27 @@ def wrapped_func(*args, **kwargs):
176176

177177
# if callsite source was not provided, attempt to
178178
# capture this info where the atom was defined
179-
if not callsite_source and callsite_filename:
180-
try:
181-
with open(callsite_filename, 'r') as f:
182-
lines = f.readlines()
183-
lineno = callsite_lineno or 0
184-
callsite_source = lines[lineno - 1].strip() if 0 < lineno <= len(lines) else ""
185-
self.callsite_metadata['callsite_source'] = callsite_source
186-
187-
except Exception:
188-
pass
179+
#
180+
# TODO(preswald): Centralize source line buffering per filename in the service layer.
181+
# This would allow both the AST transformer and Atom class to fetch source snippets
182+
# without reopening the file. Until then, skip this fallback to avoid redundant I/O.
183+
#
184+
# if not callsite_source and callsite_filename:
185+
# try:
186+
# with open(callsite_filename, 'r') as f:
187+
# lines = f.readlines()
188+
# lineno = callsite_lineno or 0
189+
# callsite_source = lines[lineno - 1].strip() if 0 < lineno <= len(lines) else ""
190+
# self.callsite_metadata['callsite_source'] = callsite_source
191+
192+
# except Exception:
193+
# pass
189194

190195
register_error(
191196
type="runtime",
192197
filename=callsite_filename or "<unknown>",
193198
lineno=callsite_lineno or 0,
199+
source=callsite_source or "",
194200
message=str(e),
195201
atom_name=self.name,
196202
)

0 commit comments

Comments
 (0)