Describe the bug
"Run as Databricks Job" / notebook Job Run output fails with _a18.flatMap is not a function whenever the target notebook (or any notebook it calls via dbutils.notebook.run) contains a code/markdown cell whose nbformat source is serialized as a single string rather than a list of strings. Both forms are valid nbformat JSON, but the workflow-wrapper generator only handles the list form.
The failing code (from the installed extension's bundled out/extension.js, v2.14.1) is the notebook.workflow-wrapper.json generator:
const cells = [bootstrapJson].concat((_a17 = originalJson["cells"]) != null ? _a17 : []).map(
// Since each cell.source is a string array where each string can be
// multiple lines, we need to split each string by \n and then flatten
(cell) => {
var _a18;
return {
source: (_a18 = cell.source) == null ? void 0 : _a18.flatMap(
(line) => line.trimEnd().split(/\r?\n/)
),
type: cell.cell_type === "code" ? "code" : "not_code",
originalCell: cell
};
}
);
The comment states the assumption outright ("each cell.source is a string array") but nothing validates it. When a cell's source is a plain string (e.g. re-saved by some other tool, or written by a program using nbformat's equally-valid single-string form), _a18 is truthy, so the code takes the _a18.flatMap(...) branch — and String.prototype.flatMap doesn't exist, throwing TypeError: _a18.flatMap is not a function with no indication of which cell/file caused it.
To Reproduce
- Create a notebook (
.ipynb) with at least one cell whose source field is a single JSON string (not a list of strings), e.g.:
{
"cell_type": "code",
"id": "abc123",
"metadata": {},
"outputs": [],
"source": "print(\"hello\")\nprint(\"world\")"
}
- Open the notebook in VS Code with the Databricks extension active, targeting a real Databricks workspace/cluster.
- Run the notebook as a Databricks Job ("Run as Databricks Job" / notebook Job Run), or have it invoked as a sub-notebook via
dbutils.notebook.run from another notebook run this way.
- The Job Run output pane shows only:
_a18.flatMap is not a function — no file name, cell id, or stack trace surfaced to the user, making this very hard to diagnose without reading the extension's own bundled source.
System information:
- VS Code version: 1.134.0 (commit 110a328ea54b42367b803ec53ee0bf52ef26b419), x64, running under a WSL remote (Ubuntu) window.
- Databricks Extension Version: 2.14.1
Additional context
- Both
"source": "line1\nline2" and "source": ["line1\n", "line2"] are valid per the nbformat spec — a consuming tool shouldn't assume only one shape.
- Suggested fix: normalize
cell.source to an array before calling .flatMap, e.g.:
const rawSource = cell.source;
const sourceLines = Array.isArray(rawSource) ? rawSource : (rawSource != null ? [rawSource] : []);
source: sourceLines.flatMap((line) => line.trimEnd().split(/\r?\n/)),
- Separately: this error is also worth wrapping with the offending file/cell id in the user-facing message — as-is, a minified variable name (
_a18.flatMap is not a function) with no other context is nearly impossible for an end user to act on. We only found the root cause by grepping the extension's own bundled JS for flatMap and reading the surrounding code.
Describe the bug
"Run as Databricks Job" / notebook Job Run output fails with
_a18.flatMap is not a functionwhenever the target notebook (or any notebook it calls viadbutils.notebook.run) contains a code/markdown cell whose nbformatsourceis serialized as a single string rather than a list of strings. Both forms are valid nbformat JSON, but the workflow-wrapper generator only handles the list form.The failing code (from the installed extension's bundled
out/extension.js, v2.14.1) is thenotebook.workflow-wrapper.jsongenerator:The comment states the assumption outright ("each cell.source is a string array") but nothing validates it. When a cell's
sourceis a plain string (e.g. re-saved by some other tool, or written by a program usingnbformat's equally-valid single-string form),_a18is truthy, so the code takes the_a18.flatMap(...)branch — andString.prototype.flatMapdoesn't exist, throwingTypeError: _a18.flatMap is not a functionwith no indication of which cell/file caused it.To Reproduce
.ipynb) with at least one cell whosesourcefield is a single JSON string (not a list of strings), e.g.:{ "cell_type": "code", "id": "abc123", "metadata": {}, "outputs": [], "source": "print(\"hello\")\nprint(\"world\")" }dbutils.notebook.runfrom another notebook run this way._a18.flatMap is not a function— no file name, cell id, or stack trace surfaced to the user, making this very hard to diagnose without reading the extension's own bundled source.System information:
Additional context
"source": "line1\nline2"and"source": ["line1\n", "line2"]are valid per the nbformat spec — a consuming tool shouldn't assume only one shape.cell.sourceto an array before calling.flatMap, e.g.:_a18.flatMap is not a function) with no other context is nearly impossible for an end user to act on. We only found the root cause by grepping the extension's own bundled JS forflatMapand reading the surrounding code.