createPromptGenerator: unknown generator names produce cryptic 'creator is not a function' TypeError
Nobody has claimed this yet.
Assessment
- Difficulty
- 2/5
- Estimated time
- 1-3 hours
- Newbie friendliness
- 88/100
- Issue type
- Bug
- Clarity
- Clearly specified
- Activity status
- Quiet
- Tech stack
- typescript
- Domain
- tooling
Research direction
Start in src/prompt-generators.ts and compare createPromptGenerator with the createAgent validation pattern from issue #5. Replace the unchecked creator lookup with validation using promptGeneratorTypes, then verify that an unknown name reports the name and known generators while valid creators still run.
Written by the indexing model from the issue text.
Description
Observed behavior
When createPromptGenerator(...) is called with a tuple whose first element is not a registered generator name, the function throws a cryptic TypeError: creator is not a function instead of a helpful error that names the unknown generator and lists the known ones.
In src/prompt-generators.ts:
const creator = promptGeneratorCreators[type] as PromptGeneratorCreator;
return creator(...args);
The as PromptGeneratorCreator cast hides the fact that promptGeneratorCreators[type] can be undefined, and the subsequent call then throws inside the runtime with no useful context for the caller.
Expected behavior
createPromptGenerator should validate that type is a known prompt generator name and throw a descriptive error that lists the known names. This is the same pattern used in createAgent after issue #5 was fixed:
const creator: AgentCreator | undefined = agentCreators[type];
if (creator == null) {
throw new Error(
`Unknown agent '${type}'. Known agents: ${agentTypes.join('\n')}.`,
);
}
The fix for createPromptGenerator should be identical in spirit, surfacing promptGeneratorTypes (which is already exported from the same file) in the error message.
Minimal reproduction
import { createPromptGenerator } from 'loop-the-loop/prompt-generators';
await createPromptGenerator([
// @ts-expect-error - intentionally invalid name
'not-a-real-generator',
{ foo: 'bar' },
]);
// TypeError: creator is not a function
A real-world trigger is a typo in a CLI JSON config file (for example "per_file" instead of "per-file"). The JSON schema would reject it, but a programmatic caller or anyone bypassing the schema gets a confusing crash.
Suggested fix
Mirror the createAgent pattern in src/prompt-generators.ts:
const creator: PromptGeneratorCreator | undefined =
promptGeneratorCreators[type];
if (creator == null) {
throw new Error(
`Unknown prompt generator '${type}'. Known prompt generators: ${promptGeneratorTypes.join('\n')}.`,
);
}
return creator(...args);
Related: #5 (the same fix was applied to createAgent).
- Dominant language
- TypeScript
- Stars
- 2
- Forks
- 1
- PR merge metrics
- No merged PRs in 30d
Contributor guide
No contributing guide indexed for this repository
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
More from joewalker/loop-the-loop
-
bug S4
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal information Openbug S3
Difficulty 2/5 1-3 hours Newbie friendliness 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficulty 2/5 1-3 hours Newbie friendliness 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficulty 1/5 Under an hour Newbie friendliness 90/100
joewalker/loop-the-loop#79 ·
All issues in joewalker/loop-the-loop
Similar issues
-
calcite-components needs triage refactor
Difficulty 2/5 1-3 hours Newbie friendliness 75/100
Esri/calcite-design-system#15203 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 91/100
-
community first-timers-only good first issue hacktoberfest help wanted low hanging fruit up-for-grabs
Difficulty 1/5 Under an hour Newbie friendliness 95/100
-
Difficulty 2/5 1-3 hours Newbie friendliness 78/100
Automattic/studio#4908 ·
-
Difficulty 2/5 1-3 hours Newbie friendliness 90/100