util/config: assertRequiredString reports 'must be a string' when the property is missing, hiding 'required field omitted' errors
まだ誰も着手していません。
評価
- 難易度
- 2/5
- 見積もり時間
- 1〜3時間
- 初心者へのやさしさ
- 84/100
- issue の種類
- バグ
- 明瞭さ
- 明確に書かれている
- 活発さ
- 静か
- 技術スタック
- typescript
調査の方向性
src/prompt-generators/util/config.ts の assertRequiredString から始め、bugzilla/config.ts、gitlab/config.ts、per-file.ts、json.ts の呼び出し元を確認します。src/util/test/load-cli-config.test.ts の関連するケース、特に 696 行目と 1283 行目を実行します。完了の条件は、キーが不足している場合はフィールドが必須であると報告され、型が誤っている場合は既存のメッセージが維持されることです。
索引モデルが issue の本文から書いたものです。
説明
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.
- 主要言語
- TypeScript
- スター
- 2
- フォーク
- 1
- PR マージ指標
- 30日以内にマージされた PR はありません
環境構築
このプロジェクトには開発コンテナ、Dockerfile、コントリビューションガイドがありません。まず README を読み、一般的な手順ははじめてのコントリビューションガイドを参照してください。
はじめの一歩
- issue を最後まで読み、次にプロジェクトのコントリビューションガイドを読みます。
- 着手することを issue にコメントします — 二人が同じ作業をするのを防げます。
- リポジトリをフォークし、ブランチを切って変更します。
- issue 番号を参照したプルリクエストを送ります。
joewalker/loop-the-loop のほかの issue
-
bug S4
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
joewalker/loop-the-loop#88 ·
-
Git exec(): child killed by a signal rejects with new Error('') and loses the signal informationオープンbug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 82/100
joewalker/loop-the-loop#84 ·
-
bug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 78/100
joewalker/loop-the-loop#83 ·
-
bug S3
難易度 2/5 1〜3時間 初心者へのやさしさ 76/100
joewalker/loop-the-loop#82 ·
-
bug S4
難易度 1/5 1時間未満 初心者へのやさしさ 90/100
joewalker/loop-the-loop#79 ·
joewalker/loop-the-loop の issue をすべて見る
似ている issue
-
難易度 2/5 1〜3時間 初心者へのやさしさ 72/100
VictoriaMetrics/victorialogs-datasource#747 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 79/100
メンテナーはふだん 1 日以内に返信
-
bug from-studio
難易度 2/5 1〜3時間 初心者へのやさしさ 62/100
esengine/DeepSeek-Reasonix#14608 ·
メンテナーはふだん 1 日以内に返信
-
triage
難易度 2/5 1〜3時間 初心者へのやさしさ 75/100
getarcaneapp/arcane#4590 ·
メンテナーはふだん 1 日以内に返信
-
難易度 2/5 1〜3時間 初心者へのやさしさ 77/100
Clouditera/VulnHunter#57 ·