util/config: assertRequiredString reports 'must be a string' when the property is missing, hiding 'required field omitted' errors
Nadie ha tomado este issue todavía.
Evaluación
- Dificultad
- 2/5
- Tiempo estimado
- 1-3 horas
- Aptitud para principiantes
- 84/100
- Tipo de issue
- Error
- Claridad
- Bien especificado
- Estado de actividad
- Tranquilo
- Stack tecnológico
- typescript
Línea de trabajo
Comienza en src/prompt-generators/util/config.ts, en assertRequiredString, y luego inspecciona los llamadores en bugzilla/config.ts, gitlab/config.ts, per-file.ts y json.ts. Ejecuta los casos relevantes en src/util/test/load-cli-config.test.ts, especialmente las líneas 696 y 1283; se considera terminado cuando las claves ausentes indiquen que el campo es obligatorio, mientras que los tipos incorrectos conserven el mensaje existente.
Escrito por el modelo de indexación a partir del texto del issue.
Descripción
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.
- Lenguaje dominante
- TypeScript
- Estrellas
- 2
- Forks
- 1
- Métricas de merge de PR
- Sin PR fusionados en 30 d
Preparar el entorno
Este proyecto no incluye contenedor de desarrollo, Dockerfile ni guía de contribución, así que la configuración corre por tu cuenta: empieza por su README y consulta nuestra guía para la primera contribución para los pasos generales.
Primeros pasos
- Lee el issue completo y luego la guía de contribución del proyecto.
- Comenta en el issue que vas a ocuparte — evita que dos personas hagan lo mismo.
- Haz un fork del repositorio y trabaja en una rama.
- Abre un pull request que haga referencia al número del issue.
Más de joewalker/loop-the-loop
-
bug S4
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationAbiertobug S3
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
Dificultad 2/5 1-3 horas Aptitud para principiantes 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
Dificultad 1/5 Menos de una hora Aptitud para principiantes 90/100
joewalker/loop-the-loop#79 ·
Todos los issues de joewalker/loop-the-loop
Issues similares
-
[Bug]: Device screenshot fails with 500 on iPhone Duo (Xcode 27.2): serve-sim calls simctl without --displayPosiblemente ocupada Un pull request vinculado a esta issue está abierto o ya se fusionó. Abierto
Dificultad 2/5 1-3 horas Aptitud para principiantes 66/100
pingdotgg/t3code#24900 · 1 comentario ·
Los mantenedores suelen responder en 1 día
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 76/100
inu-appcenter/UNIDorm-web#411 ·
Los mantenedores suelen responder en 1 día
-
🐛 bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
Los mantenedores suelen responder en 2 días
-
Dificultad 2/5 1-3 horas Aptitud para principiantes 75/100
ranxianglei/billion-context#4720 ·
Los mantenedores suelen responder en 1 día
-
area:arcade game p3-medium ready-for-agent type:bug
Dificultad 2/5 1-3 horas Aptitud para principiantes 82/100
fderuiter/deruiter.dev#2840 ·
Los mantenedores suelen responder en 1 día