Summary
insertTemplateIntoTab in modules/template-insert.js (lines 318–328) handles the four insert modes (replace, prepend, append, cursor) with an implicit else branch for "append" that carries no label or comment. A developer reading the function cold cannot tell what mode value reaches the final else without mentally tracing three separate call sites.
Impact
Maintenance burden. Any future addition of a new insertMode value (e.g. inline, header) that is not yet handled by an explicit branch would silently fall into the "append" path — with no error, no log, and no indication in the code that this is a fallback rather than the intended match. The existing cursor path is already handled by a separate outer if, so the reader must hold that context while reading the inner else if/else chain.
Evidence
modules/template-insert.js lines 318–328:
} else if (resolvedBody) {
const body = await replaceVariables(resolvedBody, tabId);
if (mode === "replace") {
details.body = body;
} else if (mode === "prepend") {
const existing = await messenger.compose.getComposeDetails(tabId);
details.body = body + (existing.body || "");
} else { // ← what mode is this?
const existing = await messenger.compose.getComposeDetails(tabId);
details.body = (existing.body || "") + body;
}
}
To understand what reaches the bare else, a reader must trace:
- Line 221:
const mode = template.insertMode || "append" — defaults missing modes to "append"
- Line 250:
if (resolvedBody && mode === "cursor") — cursor mode is already dispatched above
- Line 318:
else if (resolvedBody) — the current block covers all remaining modes
The sibling function executeImport in options.js (line 705) at least adds the comment // mode === "append" or no duplicate. insertTemplateIntoTab has no such annotation.
Recommended Fix
Change the implicit else to an explicit labeled form with a defensive fallback:
} else if (mode === "append") {
const existing = await messenger.compose.getComposeDetails(tabId);
details.body = (existing.body || "") + body;
} else {
console.warn(`TemplateWing: unknown insertMode "${mode}", falling back to append`);
const existing = await messenger.compose.getComposeDetails(tabId);
details.body = (existing.body || "") + body;
}
Alternatively, add a minimal comment if keeping the single else:
} else {
// "append" (default): add template body after existing content
const existing = await messenger.compose.getComposeDetails(tabId);
details.body = (existing.body || "") + body;
}
This change is self-contained in modules/template-insert.js and takes under 5 minutes to apply.
References
Summary
insertTemplateIntoTabinmodules/template-insert.js(lines 318–328) handles the four insert modes (replace,prepend,append,cursor) with an implicitelsebranch for "append" that carries no label or comment. A developer reading the function cold cannot tell whatmodevalue reaches the finalelsewithout mentally tracing three separate call sites.Impact
Maintenance burden. Any future addition of a new
insertModevalue (e.g.inline,header) that is not yet handled by an explicit branch would silently fall into the "append" path — with no error, no log, and no indication in the code that this is a fallback rather than the intended match. The existingcursorpath is already handled by a separate outerif, so the reader must hold that context while reading the innerelse if/elsechain.Evidence
modules/template-insert.jslines 318–328:To understand what reaches the bare
else, a reader must trace:const mode = template.insertMode || "append"— defaults missing modes to "append"if (resolvedBody && mode === "cursor")— cursor mode is already dispatched aboveelse if (resolvedBody)— the current block covers all remaining modesThe sibling function
executeImportinoptions.js(line 705) at least adds the comment// mode === "append" or no duplicate.insertTemplateIntoTabhas no such annotation.Recommended Fix
Change the implicit
elseto an explicit labeled form with a defensive fallback:Alternatively, add a minimal comment if keeping the single
else:This change is self-contained in
modules/template-insert.jsand takes under 5 minutes to apply.References
executeImporthas a similar implicit fall-through inoptions.js)getComposeDetailscalls in the same prepend/append block)