util/config: assertRequiredString reports 'must be a string' when the property is missing, hiding 'required field omitted' errors
Nessuno ha ancora preso questa issue.
Valutazione
- Difficoltà
- 2/5
- Tempo stimato
- 1-3 ore
- Idoneità per principianti
- 84/100
- Tipo di issue
- Bug
- Chiarezza
- Specificata chiaramente
- Stato di attività
- Tranquilla
- Stack tecnologico
- typescript
Direzione di ricerca
Inizia in src/prompt-generators/util/config.ts, in assertRequiredString, quindi esamina i chiamanti in bugzilla/config.ts, gitlab/config.ts, per-file.ts e json.ts. Esegui i casi rilevanti in src/util/test/load-cli-config.test.ts, in particolare alle righe 696 e 1283; il lavoro è completato quando le chiavi mancanti segnalano che il campo è obbligatorio, mentre i tipi errati mantengono il messaggio esistente.
Scritto dal modello di indicizzazione a partire dal testo della issue.
Descrizione
Observed behavior
assertRequiredString in src/prompt-generators/util/config.ts (lines 63-71) uses a single error message for two distinct failure modes:
export function assertRequiredString(
value: Record<string, unknown>,
key: string,
field: string,
): void {
if (!(key in value) || typeof value[key] !== 'string') {
throw new Error(`${field} must be a string`);
}
}
If the property is entirely missing from value, the user sees:
gitlab.search.project must be a string
That is the same message they would see if they had assigned a number, null, or an array to the field. A user who forgot to add project to their config (the most common configuration mistake for a required field) gets a message that suggests they assigned the wrong type, not that they omitted the field. The existing test in src/util/__test__/load-cli-config.test.ts at line 696 actually asserts this exact misleading message for a config where project is omitted entirely.
Expected behavior
The two failure modes should produce different messages, e.g.:
- Missing key:
gitlab.search.project is required - Wrong type:
gitlab.search.project must be a string
This matches what other validators in the codebase already do for date fields (see assertRequiredDateField in bugzilla/config.ts, which also conflates the two cases but is less commonly hit). The downstream callers in bugzilla/config.ts, gitlab/config.ts, per-file.ts, and json.ts all funnel required-string validation through this helper, so fixing it once propagates.
Minimal reproduction
import { assertRequiredString } from './prompt-generators/util/config.js';
// Property entirely missing - error is misleading
assertRequiredString({}, 'foo', 'test.foo');
// Throws: \"test.foo must be a string\" (should be \"test.foo is required\")
// Property has wrong type - error is accurate
assertRequiredString({ foo: 5 }, 'foo', 'test.foo');
// Throws: \"test.foo must be a string\"
Suggested fix
Split the check into two branches with distinct messages:
export function assertRequiredString(
value: Record<string, unknown>,
key: string,
field: string,
): void {
if (!(key in value)) {
throw new Error(`${field} is required`);
}
if (typeof value[key] !== 'string') {
throw new Error(`${field} must be a string`);
}
}
Existing tests that match against the old message (e.g. load-cli-config.test.ts:696, :1283) would need to be updated to match the new "is required" message for missing-key cases.
Severity
S3 - confusing API. The behaviour is correct (the error is thrown), but the message misleads users about what they did wrong.
- Lingua principale
- TypeScript
- Stelle
- 2
- Fork
- 1
- Metriche di merge delle PR
- Nessuna PR unita negli ultimi 30g
Preparare l'ambiente
Questo progetto non fornisce container di sviluppo, Dockerfile né guida per i contributori, quindi l'ambiente è a tuo carico: parti dal suo README e consulta la nostra guida al primo contributo per i passaggi generali.
Come iniziare
- Leggi tutta la issue e poi la guida ai contributi del progetto.
- Commenta sulla issue per dire che te ne occupi tu — evita che due persone facciano lo stesso lavoro.
- Fai un fork del repository e lavora su un branch.
- Apri una pull request che faccia riferimento al numero della issue.
Altre issue di joewalker/loop-the-loop
-
bug S4
Difficoltà 2/5 1-3 ore Idoneità per principianti 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationApertabug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Difficoltà 2/5 1-3 ore Idoneità per principianti 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Difficoltà 1/5 Meno di un'ora Idoneità per principianti 90/100
joewalker/loop-the-loop#79 ·
Tutte le issue di joewalker/loop-the-loop
Issue simili
-
Add: ON Phim Viet SDApertacheck:passed streams:add
Difficoltà 2/5 1-3 ore Idoneità per principianti 64/100
I maintainer di solito rispondono entro 1 giorno
-
Subagent progress token count ignores usage.iterations and swings on multi-iteration responsesApertaarea:agents area:cost bug platform:macos
Difficoltà 2/5 1-3 ore Idoneità per principianti 77/100
anthropics/claude-code#105375 ·
I maintainer di solito rispondono entro 1 giorno
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
-
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
galaxyproject/loom#616 ·
I maintainer di solito rispondono entro 1 giorno
-
e2e-failure ready-to-code
Difficoltà 2/5 1-3 ore Idoneità per principianti 79/100
redhat-developer/rhdh-plugin-export-overlays#4580 · 1 commento ·
I maintainer di solito rispondono entro 1 giorno